两个Django项目同时运行,mod_wsgi的作用很大 [英] Two Django projects running simultaneously and mod_wsgi acting werid

查看:951
本文介绍了两个Django项目同时运行,mod_wsgi的作用很大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试同时运行两个Django项目。我恰巧是使用mod_wsgi,发现网站的行为很奇怪。也许会有一个解决方法,但是我想知道我失踪了,如何解决问题。



在apache配置中

 #设置Python环境
#由于root拥有基本上Amazon AMI和root
#上的所有内容都不能使用。在/ var / run / wsgi
#下创建一个文件夹,所有者为ec2-user和ec2-user组。
WSGISocketPrefix / var / run / wsgi
#调用守护进程名称
WSGIDaemonProcess pydaemon processes = 1 threads = 5
#调用守护进程组名称
WSGIProcessGroup pydaemon
#指向处理程序文件的位置。这将是不同的
#如果你正在使用一些其他框架。
WSGIScriptAlias / test /var/www/html/test/wsgi.py
WSGIScriptAlias / proto /var/www/html/proto/wsgi.py

Apache重新启动后,如果我连接到'/ proto',那么会显示原始站点。然而,然后,我连接到'/ test',而不重新启动Apache,原始站点仍然显示,我无法访问测试站点。



现在我重新启动Apache ,这次我先去'/ test'。测试网站出来了!但是,如果我去'/ proto',它仍然显示测试站点,而不是原始站点。



可能会发生什么?我为每个应用程序添加了SESSION_COOKIE_PATH,以防万一,但问题仍然存在。






[UPDATED]



我也试过如下,给出不同的WSGI应用组名称,但没有运气。

 别名/ cuedit /var/local/test/wsgi.py 
<位置/测试>
SetHandler wsgi-script
选项+ ExecCGI
WSGIApplicationGroup测试
< /位置>
别名/ proto /var/local/proto/wsgi.py
< Location / proto>
SetHandler wsgi-script
选项+ ExecCGI
WSGIApplicationGroup proto
< / Location>






[更新]



我从守护程序模式更改为嵌入式模式。我猜这个问题是两个实例共享相同的mod_wsgi守护进程,所以他们的命名空间相冲突。



我希望他们应该被正确处理,但是在守护进程模式下,得到它正确

解决方案

使用此作为解决方法:

 code> WSGIDaemonProcess pydaemon-1 processes = 1 threads = 5 
WSGIDaemonProcess pydaemon-2 processes = 1 threads = 5

WSGIScriptAlias / test / var / www / html / test / wsgi .py

<位置/测试>
WSGIProcessGroup pydaemon-1
WSGIApplicationGroup%{GLOBAL}
< / Location>

WSGIScriptAlias / proto /var/www/html/proto/wsgi.py

< Location / proto>
WSGIProcessGroup pydaemon-2
WSGIApplicationGroup%{GLOBAL}
< / Location>

这将强制每个应用程序进入单独的守护程序进程组,没有办法应该能够干扰每个



如果仍然无法运行,您的WSGI脚本文件有问题。


I'm trying to run two Django projects simultaneously. I happened to be using mod_wsgi, and found the site is acting weird. Perhaps there would be a workaround, but I'd like to know what I'm missing and how to solve the problem.

In the apache configuration

# 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

After Apache restarts, if I connect to '/proto', then the proto site is shown. However, then I connect to '/test', without restarting Apache, the proto site is still shown, and I cannot access to the test site.

Now I restart Apache, this time I go to '/test' first. The test site comes up! However, if I go to '/proto' it still shows the test site, not the proto site.

What could make this happen? I added SESSION_COOKIE_PATH differently for each application just in case, but the problem still exists.


[UPDATED]

I also tried as the following, to give different WSGI application group names, but without luck.

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>


[UPDATED]

I changed from the daemon mode to the embedded mode. I guess the problem was two instances shared the same mod_wsgi daemon process so their namespace collide.

I would expect they should be handled correctly, but in the daemon mode I couldn't get it right.

解决方案

Use this as a workaround:

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>

This will force each application into separate daemon process group and no way they should be able to interfere with each other.

If that still doesn't work, you have problems with your WSGI script file somehow.

这篇关于两个Django项目同时运行,mod_wsgi的作用很大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆