小编Dav*_*lar的帖子

301重定向时,nginx保留端口号

我正在尝试将第二个品牌的网络应用程序拆分为第一个品牌,并使用301重定向来重定向任何挥之不去的流量.服务器在端口8001上的Vagrant框转发中运行.我希望:

而不是https:// local-dev-url:8001/foo /(任何) 301到https:// local-dev-url:8001 /(任何东西)

而不是https:// local-dev-url:8001/adminfoo /(任何) 301到https:// local-dev-url:8001/admin /(任何东西).

这就是我所拥有的:

    location ~ /foo/?(.*)$ {
        return 301 $1/;
    }

    location ~ /adminfoo/?(.*)$ {
        return 301 admin/$1/;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header Authorization $http_authorization;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://127.0.0.1:5000;
        proxy_redirect http:// $scheme://;
    }

    location /admin/ {
        alias /hostonly/path/to/admin/stuff/;
    }
Run Code Online (Sandbox Code Playgroud)

但是,不是将https:// local-dev-url:8001/foo /重定向到https:// local-dev-url:8001 /,而是将其转换为https:// local-dev-url // …

nginx http-status-code-301 vagrant server

8
推荐指数
1
解决办法
7303
查看次数

标签 统计

http-status-code-301 ×1

nginx ×1

server ×1

vagrant ×1