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.csdn.net/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