我有一个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/;
}
这有效,但是有一个问题,当应用程序返回301响应时,主要是当用户需要登录以访问某些资源时,URL就变成了旧的.
例如,如果需要登录/ events.
http://example.com/beta/events – > http://example.com/login?next=/events/
如何在不更改应用程序代码的情况下解决此问题? (Nginx解决方案?)
最佳答案:
“This directive sets the text, which must be changed in response-header “Location” and “Refresh” in the response of the proxied server.”
所以
proxy_redirect http://example.com/ http://example.com/beta/;
当然,这仅适用于代理服务器发出的重定向.我还假设所有重定向都有同样的问题.
提示:如有必要,您可以使用多个proxy_redirect指令.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。