我有一个Django应用程序,最近我需要推出测试版.我希望保持当前正在运行的应用程序保持不变,并在Nginx的帮助下将所有请求以"/ beta"重定向到beta应用程序.这是我的conf
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 360;
proxy_pass http://localhost:8000/;
}
location /beta/ {
rewrite ^/beta/(.*)$ /$1 break;
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 360;
proxy_pass http://localhost:8001/;
}
Run Code Online (Sandbox Code Playgroud)
这有效,但是有一个问题,当应用程序返回301响应时,主要是当用户需要登录以访问某些资源时,URL就变成了旧的.
例如,如果/events需要登录.
http://example.com/beta/events - > http://example.com/login?next=/events/
如何在不更改应用程序代码的情况下解决此问题?(Nginx解决方案?)
"该指令设置文本,必须在代理服务器的响应中的响应标题"位置"和"刷新"中更改."
所以
proxy_redirect http://example.com/ http://example.com/beta/;
Run Code Online (Sandbox Code Playgroud)
当然,这仅适用于代理服务器发出的重定向.我还假设所有重定向都有同样的问题.
提示:如有必要,您可以使用多个proxy_redirect指令.
| 归档时间: |
|
| 查看次数: |
15579 次 |
| 最近记录: |