Why does the session cookie work when serving from a domain but not when using an IP?

后端 未结 3 1487
野趣味
野趣味 2020-11-27 21:22

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.

3条回答
  •  忘掉有多难
    2020-11-27 21:41

    Notice that in the workaround for localhost that @davidism posted -- https://github.com/mitsuhiko/flask/blob/master/flask/sessions.py#L211-L215 , you can patch the Flask code and change if rv == '.localhost': rv = None to simply rv = None and then the cookie domain won't be set and your cookies will work.

    You wouldn't want to do this on a real production app, but if your server is just some kind of testing/staging server without sensitive data it might be fine. I just did this to test an app over a LAN on a 192.168.x.x address and it was fine for that purpose.

提交回复
热议问题