python - 2 个 Bitnami Django 项目同时运行 Apache WSGI

标签 python django windows apache wsgi

我正在尝试使用 wsgi 在 Apache 中设置 2 个 Django 项目,我似乎在使用 apache 的 conf 文件时遇到了问题(我对此知之甚少)

我有 2 个项目(“MyTestProjOne”和“Project”- 我知道的命名:-/)

如果我重新启动 Apache 服务器并首先转到 [servername]/Project,它将启动。然而,一旦我转到 [servername]/MyTestProjOne 它说 can not match url to Project.urls 然后它反转了。

所有这些症状都是由于 wsgi 没有在守护进程模式下运行,据我通过谷歌了解,但我不知道如何修复它。

这是与此类似的问题,但是没有一个解决方案解决了这个问题,因为我无法在 Windows 机器上运行守护进程模式(据我所知)。 Deploying multiple django apps on Apache with mod_wsgi

我的 wsgi 文件用于项目一(“MyTestProjOne”)wsgi.py:

import os, sys
sys.path.append('C:/Users/user/Bitnami Django Stack projects/MyTestProjOne')
os.environ.setdefault("PYTHON_EGG_CACHE", "C:/Users/user/Bitnami Django Stack projects/MyTestProjOne/egg_cache")


from django.core.wsgi import get_wsgi_application

os.environ["DJANGO_SETTINGS_MODULE"] = "MyTestProjOne.settings"

application = get_wsgi_application()

对于项目 2(“项目”)wsgi.py:

from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = "Project.settings"

application = get_wsgi_application()

我的 Apache 的 httpd-app.conf:

<VirtualHost _default_:8007>
    DocumentRoot "C:/Bitnami/djangostack-1.8/apache2/htdocs"
      <Directory "C:/Bitnami/djangostack-1.8/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
      <IfVersion < 2.3 >
    Order allow,deny                          
    Allow from all
</IfVersion>
<IfVersion >= 2.3 >
  Require all granted
</IfVersion>
</Directory>

# Error Documents
ErrorDocument 503 /503.html

# Bitnami applications installed with a prefix URL (default)
Include "C:/Users/user/Bitnami Django Stack projects/Project/conf/httpd-app.conf"
Include "C:/Users/user/Bitnami Django Stack projects/MyTestProjOne/conf/httpd-app.conf""
</VirtualHost>

MyTestProjOne httpd-app.conf:

WSGIScriptAlias /MyTestProjOne 'C:/Users/user/Bitnami Django Stack projects/MyTestProjOne/MyTestProjOne/wsgi.py'
<Directory "C:/Users/user/Bitnami Django Stack projects/MyTestProjOne/MyTestProjOne">
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.3>
    Require all granted
</IfVersion>
WSGIApplicationGroup %{GLOBAL}
<IfVersion < 2.3 >
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.3>
    Require all granted
</IfVersion>  
</Directory>

<Directory "C:/Users/user/Bitnami Django Stack projects/MyTestProjOne">
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.3>
    Require all granted
</IfVersion>
</Directory>

Alias /staticMyTestProjOne "C:/Users/user/Bitnami Django Stack Projects/MyTestProjOne/static"

项目httpd-app.conf:

Alias /static "C:/Users/user/Bitnami Django Stack Projects/Project/static"
WSGIScriptAlias /Project 'C:/Users/user/Bitnami Django Stack projects/Project/Project/wsgi.py'

<Directory "C:/Users/user/Bitnami Django Stack projects/Project/Project">
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.3>
    Require all granted
</IfVersion>


<IfVersion < 2.3 >
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.3>
    Require all granted
</IfVersion>

</Directory>

<Directory "C:/Users/user/Bitnami Django Stack projects/Project">

WSGIApplicationGroup %{GLOBAL}
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.3>
    Require all granted
</IfVersion>
</Directory>

最佳答案

不要设置:

WSGIApplicationGroup %{GLOBAL}

您强制两个应用程序在相同的解释器上下文中运行,由于使用了环境变量,Django 不支持这种上下文。

查看相关信息:

关于python - 2 个 Bitnami Django 项目同时运行 Apache WSGI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35096738/

相关文章:

windows - 为 Windows 编译的 CUPS 服务器?

python - 在 django Multi-Tenancy 中显示主页

windows - 如何告诉 Windows 更喜欢 UnxUtils 中的 find.exe 而不是 Windows 的 find?

python - 使用 Python 的 CSV 库将数组打印为 csv 文件

python - Binance python websocket - 无响应

Django 的 Javascript 日期格式

Django order_by() 过滤器与 distinct()

c++ - 是什么导致 WriteFile 返回 ERROR_ACCESS_DENIED?

python - 如何绘制点队列?

python - 使 FastAPI WebSockets 的 CPU 密集型任务异步