Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have nginx working as a frontend to tornado (which is running an app based on Flask framework). Nginx is running on 8080 port. However when Flask generates a "301 redirect" it does not take into account the 8080 port. I get a redirect to 80 port, where I have nothing listening.

This is my nginx config for the site:

server {
    listen 8080;
    server_name localhost;

    location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
        expires off;
    }
    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Port 8080;
        proxy_pass http://127.0.0.1:5000;
    }
}

Is there a way to correct the problem?

share|improve this question

1 Answer 1

proxy_redirect is the directive you're looking for. Since the backend server is redirecting to port 80, part of the problem is there. Test tornado directly on port 5000, do the redirects work? My guess would be no. Figure out how to tweak either tornado or Flask to include the proper port in the redirect.

Even if you don't do that, nginx can handle it with proxy_redirect(s).

proxy_redirect default;
proxy_redirect http://127.0.0.1:80/ /;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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