我正在尝试为 Apache 上的特定目录设置带有 WSGI 的 Python,但出现以下错误:
mod_wsgi (pid=3857): Target WSGI script '/var/www/test/test.py' does not contain WSGI application 'application'.
我的 test.py 包含:
print 'Hello, World!'
我的 wsgi.conf 包含:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /usr/local/bin/python2.7
Alias /test/ /var/www/test/test.py
<Directory /var/www/test>
SetHandler wsgi-script
Options ExecCGI
Order deny,allow
Allow from all
</Directory>
除此之外,有趣的是,Web 浏览器返回“404 Not Found”错误,但幸运的是 error_log 更有启发性。
我做错了什么?
最佳答案
您正在使用 WSGI,就好像它是 CGI(奇怪的是没有 header )。
您需要做的是,针对您当前的问题,改编自 http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide 的以下内容
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
这样你就有了application
。
来自引用的文档。
Note that mod_wsgi requires that the WSGI application entry point be called 'application'. If you want to call it something else then you would need to configure mod_wsgi explicitly to use the other name. Thus, don't go arbitrarily changing the name of the function. If you do, even if you set up everything else correctly the application will not be found.
关于python - 在 Apache 上使用 WSGI 为目录设置 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14410455/