[英]How do I determine if my mod_wsgi application is running on HTTPS?
I've just inherited a Python application which is running under Apache 2.4, mod_wsgi 3.4 and Python 2.7. 我刚刚继承了一个在Apache 2.4,mod_wsgi 3.4和Python 2.7下运行的Python应用程序。 The same application serves both HTTP and HTTPS requests.
相同的应用程序可同时满足HTTP和HTTPS请求。
In the existing code, it is trying to determine if the reqeust was HTTPS by checking the environment: 在现有代码中,它通过检查环境来尝试确定请求是否为HTTPS:
if context.environ.get('HTTPS') not in ['on', '1']:
This check is failing, even when the connection actually was HTTPS. 即使连接实际上是HTTPS,此检查也失败。 On looking at an extended traceback showing the environment variables, I saw that
HTTPS
was not actually in the environment passed from Apache. 在查看显示环境变量的扩展追溯时,我看到
HTTPS
实际上不在从Apache传递的环境中。
So my questions are: 所以我的问题是:
Apache's mod_ssl
can be configured to set the HTTPS
environment variable, but doesn't do so by default for performance reasons. 可以将Apache的
mod_ssl
配置为设置HTTPS
环境变量,但是出于性能原因,默认情况下不这样做 。
You could explicitly enable it, but since you're using a WSGI application, it's probably a better idea to check the wsgi.url_scheme
environment variable instead; 您可以显式启用它,但由于使用的是WSGI应用程序,因此最好检查一下
wsgi.url_scheme
环境变量; the WSGI spec guarantees its presence, and it won't require any further changes to your application if you do eventually move to nginx. WSGI规范保证了它的存在,并且如果您最终移至nginx,则它不需要对应用程序进行任何进一步的更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.