How to handle redirect response properly when using Nginx as proxy server, django as backend -
i have django application , need launch beta version. want keep current running application untouched, , redirect request starts "/beta" beta app, of nginx. here 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/; }
this works, there problem, when app returns 301 response, when user needs login access resource, url becomes old one.
for example, if /events
login required.
http://example.com/beta/events -> http://example.com/login?next=/events/
how can fix without changing application code? (nginx solution?)
try proxy_redirect.
"this directive sets text, must changed in response-header "location" , "refresh" in response of proxied server."
so
proxy_redirect http://example.com/ http://example.com/beta/;
of course, applies redirects issued proxied server. i'm assuming redirects have same problem.
tip: can use more 1 proxy_redirect directive, if necessary.
Comments
Post a Comment