• 请不要在回答技术问题时复制粘贴 AI 生成的内容
zby0826
V2EX  ›  程序员

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

  •  
  •   zby0826 ·
    zhaobaiyu · Aug 5, 2016 · 3344 views
    This topic created in 3770 days ago, the information mentioned may be changed or developed.
    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;
    }
    }
    4 replies  •  2016-08-06 21:14:12 +08:00
    lhbc
    lhbc
    Aug 5, 2016 via Android
    1
    try_files $uri $uri/ /index.php?$uri =404;
    根据自己的目录、路由等情况修改即可。
    zby0826
    zby0826
    OP
    Aug 5, 2016
    2
    @lhbc 下面有写 try_files ,只是不知道怎么把 try_files 和转 https 结合起来。你可能没看懂我问题。
    iVanilla
    iVanilla
    Aug 5, 2016
    3
    那就把 url/写到前面试试:
    try_files $uri/ $uri $uri.html =404;
    bianjp
    bianjp
    Aug 6, 2016
    4
    在 80 端口的 server 块里专门配置一下 location = /blog { return https://$host/blog/; } 肯定可行。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1817 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 16:01 · PVG 00:01 · LAX 08:01 · JFK 11:01
    ♥ Do have faith in what you're doing.