Django не будет работать на Apache с mod_wsgi - PullRequest
0 голосов
/ 08 февраля 2019

Я пытаюсь заставить Django 2.2 работать на Apache 2.4 с Python 3.7 на Windows 2016 Server.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):

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

Где найти отсутствующий модуль?

...