Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask url_for ignoring port

Tags:

python

flask

I have a Flask app running on port 5000. My server admin has configured nginx to forward this to port 5001 (sorry if I have the wrong terminology: the Flask app is running on port 5000, but the app is publicly accessible at http://the_url:5001).

All routes accessed directly in the browser work, but any redirect using url_for() seem to result in the port being missed from the URL — i.e. redirect(url_for('index')) redirects to http://the_url/ rather than http://the_url:5001/ (where the @app.route("/") triggers the function index()).

How do I make sure Flask adds the correct port when redirecting? If I change the default port to 5001, the nginx configuration will not work as it expects the app to be runnning on port 5000?

like image 233
user2672537 Avatar asked Oct 14 '15 10:10

user2672537


1 Answers

add this to your Nginx config: proxy_set_header Host $http_host; or proxy_set_header Host $host:5001

read here

like image 78
jiayi Peng Avatar answered Oct 01 '22 11:10

jiayi Peng