Flask redirection error (url_for) with machine gunner + nginx

I have a problem with the redirect function (url_for) in my flash application.

Any redirect line (url_for ("index")) redirects the application from domain.com/app to ip-addr / app , where ip -addr is my own client ip machines, not the server.

This really confused me, and I don’t know exactly where this problem occurs, since it only happens on the server, and not on local testing.

Details:

I am using the reverse proxy setup found here http://flask.pocoo.org/snippets/35/ . My nginx configuration is configured like this:

location /app { proxy_set_header X-Script-Name /app; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $proxy_add_x_forwarded_for; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 60; proxy_read_timeout 60; proxy_pass http://localhost:8000/; } 

I have a shooter launching my flash app, as a upstart task. Any clues?

EDIT:

So, I reached out a bit and found that this git report had similar problems, https://github.com/omab/django-social-auth/issues/157 .

Nginx - Gunicorn serving Nginx through localhost (127.0.0.1:1234). Unfortunately, when I authenticate on social platforms, the social-auth redirect URL sends them to 127.0.0.1:1234/twitter/complete, which obviously cannot be resolved by the client browser.

My Flask app does not seem to receive a note for updating redirection routes.

+6
source share
1 answer

I have found a solution. I had to use redirect(url_for(location, _external=True)) for all my redirects.

It seems that url_for(x, _external=True) will take all the variables in my nginx proxy_set_header to build the url, and url_for(x) does not.

This works for both server and local development.

+8
source

All Articles