跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • nginx 的 location 优先级怎么没有优先=执行的?
未分類
15 1 月 2021

nginx 的 location 优先级怎么没有优先=执行的?

nginx 的 location 优先级怎么没有优先=执行的?

資深大佬 : aries910 0

看了 nginx 的 location 优先匹配不是先精准再普通最后正则么, 不知道为什么我的配置却总是直接下面的返匹配跳转 301, 换成 [ location ~ /.+ ] 也没用。。。 求大佬解答下,这是为什么~~~

server { server_name www.a.com a.com; listen 80 ; access_log /var/log/nginx/access.log; location /.well-known/acme-challenge/ { auth_basic off; allow all; root /usr/share/nginx/html; try_files $uri =404; break; }

rewrite ^(.*) https://$server_name$1 permanent; }

server { server_name www.a.com a.com; listen 443 ssl http2 ; access_log /var/log/nginx/access.log; ssl_session_timeout 5m; ssl_session_cache shared:SSL:50m; ssl_session_tickets off; ssl_certificate /etc/nginx/certs/www.a.com.crt; ssl_certificate_key /etc/nginx/certs/www.a.com.key; add_header Strict-Transport-Security “max-age=31536000” always;

root /home;

location =/ { try_files ” /index.html; }

location / { return 301 https://2.a.com$request_uri; } }

大佬有話說 (2)

  • 資深大佬 : msg7086

    try_files 跳转到 /index.html 后会触发 301 。
    你需要加一个 location = /index.html {} 来避免被 location / 带走。

  • 主 資深大佬 : aries910

    @msg7086 感谢老哥,贴子提交才发现格式都没了,感谢老哥在这么乱的排版中给出建议,谢谢!

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具