1. 下载mod_wsgi,地址:http://code.google.com/p/modwsgi/downloads/list
2. 下载完成后(我下的是mod_wsgi-3.4.tar.gz)
tar zxvf mod_wsgi-3.4.tar.gz
./configure --with-apxs=/home/aaron/httpd/bin/apxs --with-python=/usr/bin/python
make && make install
这一步完成,httpd的modules目录下应该有mod_wsgi.so
3. 修改httpd.conf文件,添加:
LoadModule wsgi_module modules/mod_wsgi.so
4. 把下面这行添加到httpd.conf文件中,可以是server scope, 或者是 VirtualHost 中(原文: The directive can be used at server scope but would normally be placed withinthe VirtualHost container for a particular site):
WSGIScriptAlia /myapp /home/aaron/httpd/python/wsgi-scripts/myapp.wsgi
WSGIScriptAlia 跟的第一个参数表示绑定到wsgi应用的路径,第二个参数是访问wsgi应用时指向服务器上的文件路径(设定这个路径时应注意最好创建一个特定的目录,不要用$HOME之类的,用户有访问权限,容易被hack)
5. 指定设定的这个路径的访问权限:
<Directory "/home/aaron/httpd/python/wsgi-scripts">
Require all granted
</Directory>
注意:上面是Apache 2.4的语法,2.2(之前)的版本语法说明可参见:http://blog.youkuaiyun.com/kittaaron/article/details/8940545
6. 写一个最简单的wsgi程序命名为myapp.wsgi(对应第4步,下面的代码是直接从http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide上拷贝的),放到/home/aaron/httpd/python/wsgi-scripts/下,
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]
7. 重启httpd。应该能从http://hostname:port/myapp访问到了,返回hello world。
参考:http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide