title: Flask redirect(url_for) error with gunricorn + nginx
body: <p>I am having a problem with the redirect(url_for) function in my flask app.</p>
  
  <p>Any redirect(url_for("index")) line redirects the application from <strong><em>domain.com/app</em></strong> to <strong><em>ip-addr/app</em></strong>, where the <strong><em>ip-addr</em></strong> is my own client machines ip, not the server's. </p>
  
  <p>This has gotten me very confused, and I don't know where exactly the issue occurs, as it only happens on the server and not on any local testing.</p>
  
  <p><strong>Details:</strong></p>
  
  <p>I am using the reverse proxy setup found here <a href="http://flask.pocoo.org/snippets/35/" rel="noreferrer">http://flask.pocoo.org/snippets/35/</a>.
  My nginx config is setup like so</p>
  
  <pre><code>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/;
          }
  </code></pre>
  
  <p>I have gunicorn running my flask app as a upstart task.
  Any hints?</p>
  
  <p>EDIT:</p>
  
  <p>So I dug around a bit and found that the this git report had similar issues, <a href="https://github.com/omab/django-social-auth/issues/157" rel="noreferrer">https://github.com/omab/django-social-auth/issues/157</a>.</p>
  
  <p><em>Nginx - Gunicorn serving to Nginx via localhost (127.0.0.1:1234). Unfortunately, when I authenticate with social platforms, the redirect URL social-auth is sending them to is 127.0.0.1:1234/twitter/complete, which obviously can't be resolved by the client's browser.</em></p>
  
  <p>It seems my Flask app is not getting the memo to update its redirect routes.</p>