title: flask+nginx+gunicorn redirect error
body: <p>I am trying to use flask + gunicorn + nginx to set up a web app. It's ok by running the script, but it has some little problem in nginx.</p>
  
  <p>In the <code>hello.py</code>, it should redirect to index after submit a form. In my local test, the index address is <a href="http://127.0.0.1:8080" rel="nofollow noreferrer">http://127.0.0.1:8080</a> and everything goes well.<br>
  With the server of nginx and gunicorn, when a submit the form, it will redirect to <a href="http://192.168.1.108/" rel="nofollow noreferrer">http://192.168.1.108/</a> instead of <a href="http://192.168.1.108:1025/" rel="nofollow noreferrer">http://192.168.1.108:1025/</a>. 192.168.1.108 here is my local ip. </p>
  
  <p>code redirect to index.html in <code>hello.py</code>, the cody is clone from <a href="https://github.com/miguelgrinberg/flasky/tree/4c" rel="nofollow noreferrer">flasky</a>。</p>
  
  <pre><code>from flask import Flask, render_template, session, redirect, url_for, flash
  from flask_script import Manager
  from flask_bootstrap import Bootstrap
  from flask_moment import Moment
  from flask_wtf import Form
  from wtforms import StringField, SubmitField
  from wtforms.validators import Required
  from werkzeug.contrib.fixers import ProxyFix
  
  
  app = Flask(__name__)
  app.wsgi_app = ProxyFix(app.wsgi_app)
  app.config['SECRET_KEY'] = 'hard to guess string'
  
  manager = Manager(app)
  bootstrap = Bootstrap(app)
  moment = Moment(app)
  
  
  class NameForm(Form):
      name = StringField('What is your name?', validators=[Required()])
      submit = SubmitField('Submit')
  
  
  @app.route('/', methods=['GET', 'POST'])
  def index():
      form = NameForm()
      if form.validate_on_submit():
          old_name = session.get('name')
          if old_name is not None and old_name != form.name.data:
              flash('Looks like you have changed your name!')
          session['name'] = form.name.data
          return redirect(url_for('index'))
      return render_template('index.html', form=form, name=session.get('name'))
  
  
  if __name__ == '__main__':
      manager.run()
  </code></pre>
  
  <p>setting in the nginx：</p>
  
  <pre><code>worker_processes  2;
  events {
      worker_connections  1024;
  }
  http {
      include       mime.types;
      default_type  application/octet-stream;
      sendfile        on;
      server {
          listen       1025;
          server_name  127.0.0.1:8080;
  
          #charset koi8-r;
  
          #access_log  logs/host.access.log  main;
  
          location / {
              proxy_pass http://127.0.0.1:8080;   # gunicorn host address
              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          }
      }
  }
  </code></pre>
  
  <p>Running gunicorn by<code>gunicorn -w 2 -b 127.0.0.1:8080 manage:app</code>.
  I think there is something wrong in the nginx configue.</p>