使用mod_wsgi运行Python的Apache

我需要帮助build立一个本地的Apache2来运行Python。 在运行Mountain Lion的Mac上,使用html,php和mysql工作得很好。

Python运行。 通过MacPorts安装mod_wsgi,并在将以下内容添加到httpd.conf后检查它是否已被Apache加载:

LoadModule wsgi_module modules/mod_wsgi.so <Directory /opt/local/apache2/htdocs> AddHandler wsgi-script .py Options +ExecCGI Order deny,allow Allow from all </Directory> 

把我的index.py文件放到htdocs中:

 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] 

给整个path/opt/local/apache2/htdocs/index.py提供chmod 777权限

无论我做什么,我都会收到“禁止访问”,您无权访问此服务器上的/index.py。 去localhost / index.py。

Apache错误日志说:

 [Thu Aug 30 17:46:46 2012] [error] [client 127.0.0.1] Options ExecCGI is off in this directory: /opt/local/apache2/htdocs/index.py, referer: http://localhost/ 

我该如何解决这个权限问题? 什么是Options ExecCGI?

尝试使用.wsgi扩展名而不是.py。 你可能在你的Apache设置中有一个相冲突的定义,说.py是一个CGI脚本。 还可以使用WSGIScriptAlias优先于AddHandler方法来设置mod_wsgi。 请参阅文档:

http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines