Stop nginx reverse proxy from redirecting
There are several similar questions but I haven't been able to figure out how to fix my problem.
I am running an instance of nginx on port 80 which acts as a reverse proxy for some other instances of nginx (which are reverse proxying for gunicorn running different instances of a django application.)
When I navigate to gaiadev1/, it works. when I login, a redirect occurs which sends the application to gaiadev:8080. I want to stop this redirect from occurring, but I'm not sure how to.
Here is the conf for the proxy on port 80:
upstream gaiadev1 {
server 127.0.0.1:8001;
keepalive 32;
}
upstream gaiatest1 {
server 127.0.0.1:9001;
keepalive 32;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name gaiadev1;
location / {
proxy_pass http://gaiadev1;
}
}
server {
listen 80;
listen [::]:80;
server_name gaiatest1;
location / {
proxy_pass http://gaiatest1;
}
}
and here is the conf for the nginx instances running the applications:
upstream gaia {
server %s;
keepalive 32;
}
server {
listen %s default_server;
listen [::]:%s default_server ipv6only=on;
# Make site accessible from http://localhost/
server_name localhost;
location /static/ {
root /gaia;
index index.html;
}
location / {
proxy_pass http://gaia;
}
}
After some fumbling around with the nginx documentation, I found a setting for proxy_redirect which solves the issue.
location / {
proxy_pass http://gaiatest1;
proxy_redirect http://$proxy_host:9001 http://$host:80;
}