我有两个应用程序具有几乎相同的代码库(相同的功能,只是不同的品牌),我正在尝试使用 mod_wsgi 和 apache 进行虚拟托管。
两个应用程序的虚拟主机设置(在两个单独的文件中)是相同的(当然路径除外)
WSGIPythonHome /home/ubuntu/BASELINE
<VirtualHost *:80>
ServerName appA.com
ServerAlias www.appA.com
ServerAdmin admin@appA.com
DocumentRoot /home/ubuntu/appA_virtualenv/appA-server/appA
ErrorLog /home/ubuntu/appA_virtualenv/appA-server/error.log
CustomLog /home/ubuntu/appA_virtualenv/appA-server/access.log combined
Alias /static/ /home/ubuntu/appA_virtualenv/appA-server/appA/appA/static/
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess appA user=www-data group=www-data \
python-path=/home/ubuntu/appA_virtualenv/lib/python2.7/site-packages/ \
home=/home/ubuntu/appA_virtualenv/appA-server/appA/
WSGIProcessGroup appA
WSGIScriptAlias / /home/ubuntu/appA_virtualenv/appA-server/appA.wsgi
<Directory /home/ubuntu/appA_virtualenv/appA-server>
WSGIProcessGroup appA
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
.
<VirtualHost *:80>
ServerName appB.com
ServerAlias www.appB.com
ServerAdmin admin@appB.com
DocumentRoot /home/ubuntu/appB_virtualenv/server/appB
ErrorLog /home/ubuntu/appB_virtualenv/server/error.log
CustomLog /home/ubuntu/appB_virtualenv/server/access.log combined
Alias /static/ /home/ubuntu/appB_virtualenv/server/appB/appB/static/
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess appB user=www-data group=www-data \
python-path=/home/ubuntu/appB_virtualenv/lib/python2.7/site-packages/ \
home=/home/ubuntu/appB_virtualenv/server/appB/
WSGIProcessGroup appB
WSGIScriptAlias / /home/ubuntu/appB_virtualenv/server/appB.wsgi
<Directory /home/ubuntu/appB_virtualenv/server>
WSGIProcessGroup appB
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
的内容appA.wsgi
import os
os.environ['PYTHON_EGG_CACHE'] = '/home/ubuntu/appA_virtualenv/appA-server/python-eggs'
from pyramid.paster import get_app, setup_logging
ini_path = '/home/ubuntu/appA_virtualenv/appA-server/appA/development.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main')
的内容appB.wsgi
import os
os.environ['PYTHON_EGG_CACHE'] = '/home/ubuntu/appB_virtualenv/server/python-eggs'
from pyramid.paster import get_app, setup_logging
ini_path = '/home/ubuntu/appB_virtualenv/server/appB/development.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main')
我在 apache 中启用了这两个站点,并意识到在访问 appA 时,会加载 appB 目录中的 python 脚本。我通过在两个应用程序中添加一个print
语句来确认这一点,__init__.py
即使我尝试访问 appA 也会打印 appB 的文本。
然后我禁用了 appB $ sudo a2dissite appB
。appB.com 无法加载,但 appA.com 仍在加载 appB 的代码...
我将以下内容添加到appB __init__.py
(注意:不是appA)
print sys.path[0]
print os.getcwd()
输出是
/home/ubuntu/appA_virtualenv/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg
/home/ubuntu/appA_virtualenv/appA-server/appA
这超出了我的理解,因为输出正确指向 appA 的目录,但print
被添加到__init__.py
位于/home/ubuntu/appB_virtualenv/server/appB/appB/__init__.py
另外,我已经禁用了 appB 并且 apache 设置不再引用 appB 的目录,那为什么 appA 还在加载 appB 的脚本?!
我究竟做错了什么?我需要更改哪些设置才能让 appA 将脚本加载到自己的目录中?谢谢
Graham 建议的额外检查
- 守护进程模式:
mod_wsgi.process_group = 'appA'
- 主要翻译:
mod_wsgi.application_group = ''
PATH_TRANSLATED: '/home/ubuntu/appA_virtualenv/appA-server/appA.wsgi/'
SERVER_NAME: 'appA.com'
SCRIPT_FILENAME: '/home/ubuntu/appA_virtualenv/appA-server/appA.wsgi'
mod_wsgi.application_group: ''
mod_wsgi.process_group: 'appA'
mod_wsgi.version: (3, 4)