我正在尝试同时运行两个Django项目。我碰巧使用mod_wsgi,发现该网站表现得很奇怪。也许会有一个解决方法,但我想知道我错过了什么,以及如何解决问题。
在apache配置中
# Setup the Python environment
# As root owns basically everything on a Amazon AMI and root
# cannot be used. Create a folder under /var/run/wsgi
# with the owner as ec2-user and group ec2-user.
WSGISocketPrefix /var/run/wsgi
# Call your daemon process a name
WSGIDaemonProcess pydaemon processes=1 threads=5
# Call your daemon process group a name
WSGIProcessGroup pydaemon
# Point to where the handler file is. This will be different
# If you are using some other framework.
WSGIScriptAlias /test /var/www/html/test/wsgi.py
WSGIScriptAlias /proto /var/www/html/proto/wsgi.py
Apache重新启动后,如果我连接到'/ proto',则会显示proto站点。但是,然后我连接到'/ test',没有重启Apache,原始站点仍然显示,我无法访问测试站点。
现在我重启Apache,这次我先去'/ test'。测试网站出现了!但是,如果我去'/ proto',它仍会显示测试网站,而不是原型网站。
有什么可以让这种情况发生?为了防万一,我为每个应用程序添加了不同的SESSION_COOKIE_PATH,但问题仍然存在。
[增订]
我还尝试如下,给出不同的WSGI应用程序组名称,但没有运气。
Alias /cuedit /var/local/test/wsgi.py
<Location /test>
SetHandler wsgi-script
Options +ExecCGI
WSGIApplicationGroup test
</Location>
Alias /proto /var/local/proto/wsgi.py
<Location /proto>
SetHandler wsgi-script
Options +ExecCGI
WSGIApplicationGroup proto
</Location>
[增订]
我从守护进程模式更改为嵌入模式。我想问题是两个实例共享相同的mod_wsgi守护程序进程,因此它们的命名空间发生冲突。
我希望它们应该被正确处理,但是在守护进程模式下我无法正确处理它。
答案 0 :(得分:14)
将此作为解决方法使用:
WSGIDaemonProcess pydaemon-1 processes=1 threads=5
WSGIDaemonProcess pydaemon-2 processes=1 threads=5
WSGIScriptAlias /test /var/www/html/test/wsgi.py
<Location /test>
WSGIProcessGroup pydaemon-1
WSGIApplicationGroup %{GLOBAL}
</Location>
WSGIScriptAlias /proto /var/www/html/proto/wsgi.py
<Location /proto>
WSGIProcessGroup pydaemon-2
WSGIApplicationGroup %{GLOBAL}
</Location>
这将强制每个应用程序进入单独的守护程序进程组,并且它们不应该相互干扰。
如果仍然无效,那么您的WSGI脚本文件会出现问题。
答案 1 :(得分:4)
我还有2个Django项目,但是每个项目都运行在不同的端口(httpd config)上,它看起来像这样:
<VirtualHost *:80>
ServerAdmin xx
ServerName xx
ServerAlias xx
ErrorLog /path/to/first/project/logs/error.log
CustomLog /path/to/first/project/logs/access.log combined
Alias /static/ /path/to/first/project/sitestatic
WSGIDaemonProcess app processes=1 threads=15 display-name=%{GROUP}
WSGIProcessGroup app
WSGIScriptAlias / /path/to/first/project/django.wsgi
<Directory /path/to/first/project/apache>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin xx
ServerName xx
ServerAlias xx
ErrorLog /path/to/second/project/logs/error.log
CustomLog /path/to/second/project/logs/access.log combined
WSGIDaemonProcess app1 processes=1 threads=15 display-name=%{GROUP}
WSGIProcessGroup app1
WSGIScriptAlias / /path/to/second/project/apache/django.wsgi
<Directory /path/to/second/project/apache>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
答案 2 :(得分:1)
问题可能与Apache在WSGI应用程序之间共享Python子解释器有关。尝试将此添加到Apache配置以避免共享:
WSGIApplicationGroup %{GLOBAL}
检查this blog post以获得深入的解释和其他提示(也请查看评论)。
答案 3 :(得分:0)
无法评论格雷厄姆给出的答案,所以加入我自己的答案。
我的问题确实是Python解释器,但我还必须为每个解释器添加python-path。以下是一个示例配置:
WSGIDaemonProcess py_app1 processes=1 threads=5 python-path=/path/to/app1
WSGIScriptAlias /app1 /path/to/app1/wsgi.py
<Directory /path/to/app1>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
<Location /app1>
WSGIProcessGroup py_app1
WSGIApplicationGroup %{GLOBAL}
</Location>
WSGIDaemonProcess py_app2 processes=1 threads=5 python-path=/path/to/app2
WSGIScriptAlias /app2 /path/to/app2/wsgi.py
<Directory /path/to/app2>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
<Location /app2>
WSGIProcessGroup py_app2
WSGIApplicationGroup %{GLOBAL}
</Location>