我有一个Django应用程序,最近我需要启动一个测试版本。我希望保持当前正在运行的应用程序不变,并在Nginx的帮助下将所有以“/ beta”开头的请求重定向到测试版应用程序。这是我的conf如何在使用Nginx作为代理服务器时正确处理重定向响应,django作为后端
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解决方案?)
你不应该在django后端/中间件而不是nginx中处理它吗? – karthikr
使用子域beta.example.com是一个更好的解决方案,对我来说 –
我是否正确理解您正在使用Django的内置开发服务器作为代理的后端?你真的不应该这样做。如果你使用的是uwsgi,你的问题会有一个非常简单的解决方案(并且你的应用会更快) –