环境
MacOS Sierra 10.12.4 (16E195)。自带 Apache,自带Python。
- 配置文件位置:/private/etc/apache2
- 用户配置文件位置:/private/etc/apache2/users
- 日志文件位置:/private/var/log/apache2
安装 mod_wsgi
sudo pip install mod_wsgi
安装后,会生成 mod_wsgi.so 文件,位置如下,可直接引用该文件
/Library/Python/2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so
配置Apache
/private/etc/apache2/httpd.conf
用户配置
启用 httpd-userdir.conf
# User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf
修改用户配置文件,设置主目录等等
/private/etc/apache2/users/dongyg.conf
连接数管理
# Server-pool management (MPM specific)
Include /private/etc/apache2/extra/httpd-mpm.conf
apachectl -l
查看 mpm
Compiled in modules:
core.c
mod_so.c
http_core.c
prefork.c
把连接数改大一些
<IfModule mpm_prefork_module>
StartServers 1
MinSpareServers 1
MaxSpareServers 10
MaxRequestWorkers 2500
MaxConnectionsPerChild 0
</IfModule>
配置I3
httpd.conf 末尾默认有一行
Include /private/etc/apache2/other/*.conf
所以,我们可以在/private/etc/apache2/other/
下为I3创建一个独立的配置文件i3.conf
。
LoadModule wsgi_module /Library/Python/2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so
AddType text/html .py
WSGIScriptAlias /i3 /Users/dongyg/enfoCode/WebTemplate/index.wsgi/
Alias /i3/static /Users/dongyg/enfoCode/WebTemplate/static/
<Directory /Users/dongyg/enfoCode/WebTemplate/>
AllowOverride None
Options None
Require all granted
</Directory>
<Directory /Users/dongyg/enfoCode/WebplatModules/modules/>
AllowOverride None
Options None
Require all granted
</Directory>
WSGIApplicationGroup %{GLOBAL}
AcceptFilter http none
AcceptFilter https none
EnableSendfile Off
EnableMMAP off
#有几个需要写的文件,在MacOS上要修改文件的权限,chmod 666 filename。例如:modules/cpublic.py, uploads
#chmod 444 WebTemplate/helpers/word4.data
#chmod 666 WebTemplate/uploads
#chmod 777 WebplatModules/modules/cpublic.py
运行
sudo apachectl start
sudo apachectl stop
sudo apachectl restart