【问题标题】:Two Django websites on Windows ApacheWindows Apache 上的两个 Django 网站
【发布时间】:2021-11-30 05:33:04
【问题描述】:

我正在尝试在 Windows 上托管两个 Django 网站(因此没有 WSGIdaemonprocess)。当我只主持其中一个时,它工作得很好。现在它仍然有效(主路径“/”名为 magazyn)。但是第二个(名为 awizacje 的路径“/awizacje”)会引发内部服务器错误。 Apache 日志中的完整错误消息如下所示:

C:\A\34\s\Modules\_decimal\libmpdec\context.c:57: warning: mpd_setminalloc: ignoring request to set MPD_MINALLOC a second time

[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] mod_wsgi (pid=6268): Failed to exec Python script file 'C:/var/www2/awizacje/rootkat/awizacje/wsgi.py'.
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] mod_wsgi (pid=6268): Exception occurred processing WSGI script 'C:/var/www2/awizacje/rootkat/awizacje/wsgi.py'.
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] Traceback (most recent call last):\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "C:/var/www2/awizacje/rootkat/awizacje/wsgi.py", line 19, in <module>\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]     application = get_wsgi_application()\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]     django.setup(set_prefix=False)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\__init__.py", line 19, in setup\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\conf\\__init__.py", line 76, in __getattr__\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]     self._setup(name)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\conf\\__init__.py", line 63, in _setup\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]     self._wrapped = Settings(settings_module)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\conf\\__init__.py", line 142, in __init__\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]     mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "C:\\Python39\\lib\\importlib\\__init__.py", line 127, in import_module\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]     return _bootstrap._gcd_import(name[level:], package, level)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532]   File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] ModuleNotFoundError: No module named 'awizacje'\r

我的httpd.conf 看起来像这样:

WSGIPythonHome "C:/var/www/magazyn/env39"
WSGIPythonPath "C:/var/www/magazyn/venv/Lib/site-packages;C:/var/www/magazyn/rootkat/"

    ServerName www.magazyn-stolarz.pl
    LoadFile "C:/Python39/python39.dll"
    LoadModule wsgi_module "C:/var/www/magazyn/env39/lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win_amd64.pyd"
    WSGIScriptAlias /awizacje "C:/var/www2/awizacje/rootkat/awizacje/wsgi.py"
    WSGIScriptAlias / "C:/var/www/magazyn/rootkat/magazyn/wsgi.py"

    <Directory "C:/var/www/magazyn/rootkat/magazyn/">
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static "C:/var/www/static/"
    <Directory "C:/var/www/static/">
        Require all granted
    </Directory>
    
    <Directory "C:/var/www2/awizacje/rootkat/awizacje/">
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    Alias /statica "C:/var/www2/static/"
    <Directory "C:/var/www2/static/">
        Require all granted
    </Directory>

我在 'awizacje' 项目中的 wsgi.py 设置:

"""
WSGI config for magazyn project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""

import os
import sys
import site

from django.core.wsgi import get_wsgi_application
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awizacje.settings')
os.environ["DJANGO_SETTINGS_MODULE"] = "awizacje.settings"

application = get_wsgi_application()

site.addsitedir('C:/var/www2/awizacje/venv/Lib/site-packages')
sys.path.append('C:/var/www2/awizacje')
sys.path.append('C:/var/www2/awizacje/rootkat')

我做错了什么?很遗憾,我不能使用非常简单的 Linux。

【问题讨论】:

    标签: django apache mod-wsgi


    【解决方案1】:

    看来我缺少的是在wsgi.py 中的get_wsgi_application() 命令之前附加目录

    """
    WSGI config for magazyn project.
    
    It exposes the WSGI callable as a module-level variable named ``application``.
    
    For more information on this file, see
    https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
    """
    
    import os
    import sys
    import site
    
    from django.core.wsgi import get_wsgi_application
    #os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awizacje.settings')
    os.environ["DJANGO_SETTINGS_MODULE"] = "awizacje.settings"
    
    application = get_wsgi_application()
    
    site.addsitedir('C:/var/www2/awizacje/venv/Lib/site-packages')
    sys.path.append('C:/var/www2/awizacje')
    sys.path.append('C:/var/www2/awizacje/rootkat')
    

    【讨论】:

      猜你喜欢
      • 2021-01-15
      • 2016-10-12
      • 2011-08-23
      • 2021-11-30
      • 1970-01-01
      • 2017-09-03
      • 1970-01-01
      • 2017-05-16
      相关资源
      最近更新 更多