【发布时间】:2017-09-09 21:02:49
【问题描述】:
我正在尝试将网络应用的第二个品牌合并到第一个品牌中,并使用 301 重定向来重定向任何挥之不去的流量。服务器在 8001 端口上转发的 Vagrant box 中运行。我想要:
而不是 https://local-dev-url:8001/foo/(anything) 301 到 https://local-dev-url:8001/(anything)
而不是 https://local-dev-url:8001/adminfoo/(anything) 301 到 https://local-dev-url:8001/admin/(anything)。
这是我所拥有的:
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/;
}
但是,不是将 https://local-dev-url:8001/foo/ 重定向到 https://local-dev-url:8001/,而是将 301 重定向到 https://local-dev-url//。 (没有端口号,额外的斜杠。)我已经看到了对重定向 URL 进行硬编码的答案,但是由于我与许多其他开发人员一起工作并且我们都有唯一的本地开发 URL,唯一一致的部分是: 8001 端口号。
有没有办法将 301 配置为按需要工作?
【问题讨论】:
-
这个服务器在监听哪个端口?你是转发 8001 到 80 吗?
-
@RichardSmith 端口 443,而不是 80。
标签: nginx server vagrant http-status-code-301