https 网站的子目录,不加斜线时,怎么样可以只跳转一次即可?

2016-08-05 19:37:24 +08:00
 zby0826
nginx 用上了 https , blog 是网站的子目录,可是在现在的配置下,我访问 http://example.com/blog 的时候,要跳转两次,先跳到 https://example.com/blog ,再跳到 https://example.com/blog/ ,再然后才返回 200 。

怎么写可以只跳转一次就好,直接从 80 跳到 443 ,并加上斜线?

以下是当前配置:
server {
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$host$request_uri;
}


server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com;
root ...;
...

location /blog {
error_page 404 /blog/404.html;
try_files $uri $uri.html $uri/ =404;
}
}
2677 次点击
所在节点    程序员
4 条回复
lhbc
2016-08-05 19:47:04 +08:00
try_files $uri $uri/ /index.php?$uri =404;
根据自己的目录、路由等情况修改即可。
zby0826
2016-08-05 21:16:01 +08:00
@lhbc 下面有写 try_files ,只是不知道怎么把 try_files 和转 https 结合起来。你可能没看懂我问题。
iVanilla
2016-08-05 22:01:16 +08:00
那就把 url/写到前面试试:
try_files $uri/ $uri $uri.html =404;
bianjp
2016-08-06 21:14:12 +08:00
在 80 端口的 server 块里专门配置一下 location = /blog { return https://$host/blog/; } 肯定可行。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/297446

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX