title: Flask url_for ignoring port
body: <p>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 <code>http://the_url:5001</code>).</p>
  
  <p>All routes accessed directly in the browser work, but any redirect using <code>url_for()</code> seem to result in the port being missed from the URL — i.e. <code>redirect(url_for('index'))</code> redirects to <code>http://the_url/</code> rather than <code>http://the_url:5001/</code> (where the <code>@app.route("/")</code> triggers the function <code>index()</code>).</p>
  
  <p>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? </p>