<VirtualHost *:80>
WSGIDaemonProcess site1 processes=2 threads=15 python-path=/var/www/site1/site1
WSGIProcessGroup site1
WSGIApplicationGroup %{GLOBAL}
ServerAdmin webmaster@dummy-host.example.com
ServerName localhost:80
Alias /static /var/www/site1/site1/static
<Directory /var/www/site1/site1/static>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/site1/site1/site1/wsgi.py
# WSGIPythonPath /var/www/site1/site1
<Directory /var/www/site1/site1>
<Files wsgi.py>
Require all granted
</Files>
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/site1/site1/templates"
<Directory "/var/www/site1/site1/templates">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:81>
WSGIDaemonProcess site2 processes=2 threads=15 python-path=/var/www/site2/site2
WSGIProcessGroup site2
WSGIApplicationGroup %{GLOBAL}
ServerAdmin webmaster@dummy-host.example.com
ServerName localhost:81
Alias /static /var/www/site2/site2/static
<Directory /var/www/site2/site2/static>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/site2/site2/site2/wsgi.py
# WSGIPythonPath /var/www/site2/site2
<Directory /var/www/site2/site2>
<Files wsgi.py>
Require all granted
</Files>
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/site2/site2/templates"
<Directory "/var/www/site2/site2/templates">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
mod_wsgi工作在daemon模式下,python-path 表明项目包的路径,与WSGIPythonPath作用相同(WSGIPythonPath不能放在VirtualHost内使用)。
Alias /static/js及css要放在WSGIScriptAlias前面,让静态文件给apache先处理。
WSGIApplicationGroup %{GLOBAL}解决apache频繁自动重启问题。