title: Why does the session cookie work when serving from a domain but not when using an IP?
body: <p>I have a Flask application with sessions that works well on my local development machine. However, when I try to deploy it on an Amazon server, sessions do not seem to work. </p>
  
  <p>More specifically, the session cookie is not set. I can, however, set normal cookies. I made sure I have a static secure key, as others have indicated that might be an issue. The only difference is in how the server is set up. During development, I use</p>
  
  <pre><code>app.run()
  </code></pre>
  
  <p>to run locally. When deployed, I use</p>
  
  <pre><code>app.config['SERVER_NAME'] = '12.34.56.78'  # &lt;-- insert a "real" IP
  app.run(host='0.0.0.0', port=80)
  </code></pre>
  
  <p>I suspect the problem might be in the above, but am not completely certain.</p>
  
  <p>The session <em>does</em> seem to work on Firefox, but not Chrome.</p>
  
  <p>The following small application demonstrates the problem, with the configuration differences at the bottom:</p>
  
  <pre><code>from flask import Flask, make_response, request, session
  
  app = Flask(__name__)
  app.secret_key = 'secretKey'
  
  # this is to verify that cookies can be set
  @app.route('/setcookie')
  def set_cookie():
      response = make_response('Cookie set')
      response.set_cookie('cookie name', 'cookie value')
      return response
  
  @app.route('/getcookie')
  def get_cookie():
      if 'cookie name' in request.cookies:
          return 'Cookie found. Its value is %s.' % request.cookies['cookie name']
      else:
         return 'Cookie not found'
  
  # this is to check if sessions work
  @app.route('/setsession')
  def set_session():
      session['session name'] = 'session value'
      return 'Session set'
  
  @app.route('/getsession')
  def get_session():
      if 'session name' in session:
          return 'Session value is %s.' % session['session name']
      else:
          return 'Session value not found'
  
  if __name__ == '__main__':
      app.debug = True
  
      # windows, local development
      #app.run()  
  
      # Ubuntu
      app.config['SERVER_NAME'] = '12.34.56.78'  # &lt;-- insert a "real" IP
      app.run(host='0.0.0.0', port=80)
  </code></pre>