【发布时间】:2013-09-13 14:09:54
【问题描述】:
在 CentOS 6.3 上使用 Python 2.7、Apache + mod_wsgi 运行
当我在本地主机上时一切正常。但是,当我在 Azure 中的 vm 上运行代码时,我看不到会话信息跨页面保留。
基本上在我看来,我有类似的东西:
@frontend.route('/')
def index():
session['foo'] = 'bar'
print session['foo']
return redirect(url_for("frontend.page2"))
@frontend.route('page2')
def page2():
print session
打印输出为:
bar
<SecureCookieSession {}>
我对 apache 的 wsgi 配置是:
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com
WSGIDaemonProcess myproj threads=5 processes=5
WSGIScriptAlias / /home/mydir/myproj/apache/myproj.wsgi
<Directory /home/mydir/myproj>
WSGIScriptReloading On
WSGIProcessGroup myproj
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
我设置了 secret_key:
app.secret_key = os.urandom(24)
我尝试过设置 SERVER_NAME,但没有帮助:
app.config['SERVER_NAME'] = 'example.com'
关于如何进行更多调试的任何想法?
谢谢!
【问题讨论】:
-
您有密钥吗?会话需要它:
app.secret_key = 'something long and random' -
是的,我有密钥。谢谢。
-
您将会话存储在哪里?
-
@cababunga:我使用的是 Flask 的默认存储。问题已解决,正是 mata 指出的问题。