简体   繁体   English

在一台Xampp Windows Apache Mod_WSGI服务器上部署两个Django项目

[英]Deploy two Django projects on one Xampp Windows Apache Mod_WSGI server

I want to deploy multiple Django projects on one server. 我想在一台服务器上部署多个Django项目。 It is Windows 32 bit Xampp. 这是Windows 32位Xampp。 mod_wsgi is 32 bit. mod_wsgi是32位。 python is 32 bit. python是32位。 Django is ver 1.7.3. Django是1.7.3版。

I have read lots of posts and tried many things but I can't get past this problem. 我读了很多文章,尝试了很多事情,但我无法克服这个问题。

The following error shown in the browser also indicates some version info. 浏览器中显示的以下错误也指示某些版本信息。

Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
Error 500
localhost Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.19 mod_wsgi/3.5 Python/2.7.6

I can successfully deploy one django application this way. 我可以通过这种方式成功部署一个Django应用程序。 There are no errors if I only deploy one, for example c:/p2/xampp/htdocs/django/mysite 如果仅部署一个,则没有错误,例如c:/ p2 / xampp / htdocs / django / mysite

When I add the second project I get the below error and only the first project works. 当我添加第二个项目时,出现以下错误,只有第一个项目有效。

I get the following error in the apache error.log. 我在apache error.log中收到以下错误。

mod_wsgi (pid=11184): Exception occurred processing WSGI script 'C:/p2/xampp/htdocs/django/apache/django161c.wsgi'.
~~~~~ some lines removed ~~~~~~
ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named mysite.settings

Last two lines of My httpd.conf: 我的httpd.conf的最后两行:

LoadModule wsgi_module modules/mod_wsgi.so
Include C:/p2/xampp/htdocs/django/apache/wsgi3.conf

My wsgi3.conf 我的wsgi3.conf

############
listen 8986
<VirtualHost *:8986>
Alias /static/ c:/p2/xampp/htdocs/django/mysite/static/
WSGIScriptAlias / "c:/p2/xampp/htdocs/django/apache/mysite.wsgi" 
    DocumentRoot "c:/p2/xampp/htdocs/django/mysite"
    ServerName 127.0.0.1
<Directory "c:/p2/xampp/htdocs/django/apache">
    Allow from all
</Directory>
</VirtualHost>
############
listen 8985
<VirtualHost *:8985>
WSGIScriptAlias / "c:/p2/xampp/htdocs/django/apache/django161c.wsgi" 
    DocumentRoot "c:/p2/xampp/htdocs/django/django161c"
    ServerName 127.0.0.1
<Directory "c:/p2/xampp/htdocs/django/apache">
    Allow from all
</Directory>
</VirtualHost>

My mysite.wsgi: 我的mysite.wsgi:

import os, sys
sys.path.append('c:/p2/xampp/htdocs/django/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
# works: https://www.pythonanywhere.com/forums/topic/1629/ # this is for changes to django 1.7 # 2015-01-23_Fri_14.13-PM
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

My django161c.wsgi 我的django161c.wsgi

import os, sys
sys.path.append('c:/p2/xampp/htdocs/django/django161c')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Can you help me? 你能帮助我吗?

The solution is: 解决方案是:

There are two 'mysite.settings' It should be 'django161c.settings' in the django161c.wsgi . 有两个“mysite.settings”这应该是在django161c.wsgi“django161c.settings”。

This fixed it. 这样就解决了。

Then it kept asking me to login repeatedly in each project. 然后它一直要求我在每个项目中重复登录。

I then added 然后我加了

SESSION_COOKIE_PATH = "/django161c" SESSION_COOKIE_PATH =“ / django161c”

to the settings.py so that each site did not share the same sessionid cookie. settings.py,这样每个站点就不会共享相同的sessionid cookie。

I did the same for the 'mysite' project. 我对“ mysite”项目也做了同样的事情。

SESSION_COOKIE_PATH = "/mysite" SESSION_COOKIE_PATH =“ / mysite”

Also, I matched the compiler and versions of mod_wsgi 另外,我匹配了mod_wsgi的编译器和版本

I used python 2.7.9 apache 2.4 all 32 bit and all vc9 compiler The mod_wsgi was downloaded from this post: 我使用python 2.7.9 apache 2.4所有32位和所有vc9编译器mod_wsgi从这篇文章下载:

https://groups.google.com/forum/#!topic/modwsgi/SxedM5UKvic https://groups.google.com/forum/#!topic/modwsgi/SxedM5UKvic

I named the module mod_wsgi-442-ap24-w32-vc9-py279.so 我将模块命名为mod_wsgi-442-ap24-w32-vc9-py279.so

This way I know it is mod_wsgi 4.4.2, all compiled with vc9, for apache 2.4, python 2.7.9, all win32. 这样我就知道它是mod_wsgi 4.4.2,全部使用vc9编译,适用于Apache 2.4,python 2.7.9,全部win32。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM