是的,你是对的,mod_python 不适用于 Python 2.7。所以 mod_wsgi 是您的最佳选择。
我推荐 AMPPS,因为默认情况下使用 mod_python 和 python 2.5 启用 python 环境。AMPPS网站
如果你还想继续
在 httpd.conf 中添加这一行
LoadModule wsgi_module modules/mod_wsgi.so
取消 httpd.conf 中该行的注释
Include conf/extra/httpd-vhosts.conf
打开虚拟主机文件 httpd-vhosts.conf 并添加
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
<Directory "path/to/directory/in/which/wsgi_test.wsgi/is/present">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName 127.0.0.1
ServerAlias 127.0.0.1
WSGIScriptAlias /wsgi "path/to/wsgi_test.wsgi"
DocumentRoot "path/to/htdocs"
ErrorLog "path/to/log.err"
CustomLog "path/to/log.log" combined
</VirtualHost>
在 wsgi_test.wsgi 中添加以下行
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]
注意:不要在 htdocs 中创建测试目录。因为我还没有尝试过。这些步骤在 AMPPS 中对我有用。 :)
然后在您喜欢的浏览器中访问 127.0.0.1/wsgi。你会看到你好世界!。
如果没看到请关注快速配置指南
OR
您可以在 httpd.conf 中添加这些行
<IfModule wsgi_module>
<Directory path/to/directory>
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
WSGIScriptAlias /wsgi path/to/wsgi_test.wsgi
</IfModule>