5

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;
    }
}
  • Remove proxy_redirect directive – Alexey Ten Aug 4 '15 at 19:44
  • @AlexeyTen i removed that. I had been playing around with different settings. I have updated the post to use the simplest conf I have that reproduces the issue. – canisrufus Aug 4 '15 at 19:59
0

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;
}
  • Perhaps @canisrufus you could mark this answer as accepted so it doesn't get bumped to the home page to be answered. – Tim Sep 17 '17 at 0:31
  • Looks a good solution. I still rather create a simpler 301 redirection for each domain name. – Bert Nov 20 '17 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.