本章完成以下内容:
- 版本需求
- Apache配置
- wsgi启动程序
如果下面这一点没有做到,整个过程有99%的可能性会失败。
Apache,mod_wsgi和Python都必须用相同版本的C/C++编译器生成,它们要么是32位的,要么是64位的,不能混用。
目前(2016-09-05)推荐的为Apache 2.4, Python2.7.11, mod_wsgi VC9版本。
打开 httpd.conf 文件:
打开 httpd-vhosts.conf 文件:
这个文件里面一般都是使用#注释掉了。假设我们的程序使用8000端口:
# Apache 2.4版本
Listen 8000
NameVirtualHost *:8000
<VirtualHost *:8000>
ServerName test.com
ServerAlias www.test.com
ServerAdmin root@test.com
DocumentRoot "F:/web"
ErrorLog "F:/web/error.log"
WSGIScriptAlias / F:/web/run.wsgi
Alias /static F:/web/static
<Directory "F:/web">
#Options +ExecCGI
#AddHandler cgi-script .py
Options -Indexes +FollowSymLinks
Require all granted # ver 2.4
AllowOverride All
WSGIScriptReloading On
</Directory>
</VirtualHost>
其中WSGIScriptAlias / F:/web/run.wsgi
指定了启动脚本为 run.wsgi。
# run.wsgi
import sys
sys.path.insert(0, 'F:/web')
from blog import app as application
如此,apache程序会主动加载blog模块中的app作为应用实例。