Django无法使用mod_wsgi在Apache上运行

时间:2019-02-08 09:53:07

标签: python django apache mod-wsgi

我正在尝试让Django 2.2在Windows 2016 Server上的Python 3.7上的Apache 2.4上运行。 Django在开发服务器(manage.py runserver)上运行良好,并且Apache服务器运行并且可以在网络上访问,但是Django在Apache上没有运行。这是我正在运行的Apache配置(httpd.conf):

ServerName localhost:80


<Directory />
    AllowOverride none
    Require all denied
</Directory>

LoadFile "c:/program files/python37/python37.dll"
LoadModule wsgi_module "c:/program files/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/program files/python37"
WSGIScriptAlias \ "D:\Django\myproject\myproject\wsgi.py"
WSGIPythonPath "D:\Django\myproject\myproject"

<Directory "D:\Django\myproject\myproject">
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">

    Options Indexes FollowSymLinks
    AllowOverride None    
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

这是我的wsgi.py(与manage.py startproject期间生成的内容相同):

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')

application = get_wsgi_application()

当我尝试在浏览器中加载http://myserver时,会显示Apache Defualt页面,但如果尝试加载http://myserver:8000则会出现连接错误。

编辑:

以下是error.log的相关条目:

[Fri Feb 08 11:30:15.853857 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Python home c:/program files/python37.
[Fri Feb 08 11:30:15.853857 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Initializing Python.
[Fri Feb 08 11:30:15.869484 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Attach interpreter ''.
[Fri Feb 08 11:30:15.885109 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Adding 'D:\\Django\\myproject\\myproject' to path.
[Fri Feb 08 11:30:15.885109 2019] [wsgi:info] [pid 864:tid 436] mod_wsgi (pid=864): Imported 'mod_wsgi'.

看起来它可以很好地加载,但它甚至都没有尝试在端口8000上进行监听。

Edit2:

所以我对WSGIScriptAlias的设置似乎有误。现在,至少要尝试加载WSGI应用程序。

[Fri Feb 08 12:28:02.123312 2019] [wsgi:info] [pid 856:tid 1212] mod_wsgi (pid=856): Create interpreter 'localhost|/test'.
[Fri Feb 08 12:28:02.138940 2019] [wsgi:info] [pid 856:tid 1212] mod_wsgi (pid=856): Adding 'D:\\Django\\kte_test\\kte_test' to path.
[Fri Feb 08 12:28:02.138940 2019] [wsgi:info] [pid 856:tid 1212] [client 172.16.27.254:51858] mod_wsgi (pid=856, process='', application='localhost|/test'): Loading Python script file 'D:/Django/kte_test/kte_test/wsgi.py'.
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] mod_wsgi (pid=856): Failed to exec Python script file 'D:/Django/kte_test/kte_test/wsgi.py'.
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] mod_wsgi (pid=856): Exception occurred processing WSGI script 'D:/Django/kte_test/kte_test/wsgi.py'.
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] Traceback (most recent call last):\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "D:/Django/kte_test/kte_test/wsgi.py", line 16, in <module>\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]     application = get_wsgi_application()\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "c:\\program files\\python37\\lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]     django.setup(set_prefix=False)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "c:\\program files\\python37\\lib\\site-packages\\django\\__init__.py", line 19, in setup\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "c:\\program files\\python37\\lib\\site-packages\\django\\conf\\__init__.py", line 57, in __getattr__\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]     self._setup(name)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "c:\\program files\\python37\\lib\\site-packages\\django\\conf\\__init__.py", line 44, in _setup\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]     self._wrapped = Settings(settings_module)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "c:\\program files\\python37\\lib\\site-packages\\django\\conf\\__init__.py", line 107, in __init__\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]     mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "c:\\program files\\python37\\lib\\importlib\\__init__.py", line 127, in import_module\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]     return _bootstrap._gcd_import(name[level:], package, level)\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "<frozen importlib._bootstrap>", line 983, in _find_and_load\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "<frozen importlib._bootstrap>", line 983, in _find_and_load\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858]   File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked\r
[Fri Feb 08 12:28:02.310819 2019] [wsgi:error] [pid 856:tid 1212] [client 172.16.27.254:51858] ModuleNotFoundError: No module named 'myproject'\r

在哪里可以找到缺少的模块?

0 个答案:

没有答案