Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;

Is there a way to correct the problem?

share|improve this question

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 /;
share|improve this answer

Your Answer


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.