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?
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).