内部服务器错误500 Apache 2.4和mod_wsgi

时间:2017-02-24 17:48:57

标签: django apache mod-wsgi

从我的apache错误日志中我得到以下输出:

[Fri Feb 24 18:44:44.617451 2017] [mpm_winnt:notice] [pid 16752:tid 684] AH00354: Child: Starting 64 worker threads.
[Fri Feb 24 18:44:49.932581 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965] mod_wsgi (pid=16752): Target WSGI script 'C:/Users/Rasmus/workspace/MainSite/src/MainSite/wsgi.py' cannot be loaded as Python module.
[Fri Feb 24 18:44:49.932581 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965] mod_wsgi (pid=16752): Exception occurred processing WSGI script 'C:/Users/Rasmus/workspace/MainSite/src/MainSite/wsgi.py'.
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965] Traceback (most recent call last):\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "C:/Users/Rasmus/workspace/MainSite/src/MainSite/wsgi.py", line 16, in <module>\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]     application = get_wsgi_application()\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "c:\\anaconda3\\lib\\site-packages\\django\\core\\wsgi.py", line 13, in get_wsgi_application\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]     django.setup()\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "c:\\anaconda3\\lib\\site-packages\\django\\__init__.py", line 17, in setup\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "c:\\anaconda3\\lib\\site-packages\\django\\conf\\__init__.py", line 55, in __getattr__\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]     self._setup(name)\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "c:\\anaconda3\\lib\\site-packages\\django\\conf\\__init__.py", line 43, in _setup\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]     self._wrapped = Settings(settings_module)\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "c:\\anaconda3\\lib\\site-packages\\django\\conf\\__init__.py", line 99, in __init__\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]     mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "c:\\anaconda3\\lib\\importlib\\__init__.py", line 126, in import_module\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]     return _bootstrap._gcd_import(name[level:], package, level)\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "<frozen importlib._bootstrap>", line 986, in _gcd_import\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "<frozen importlib._bootstrap>", line 969, in _find_and_load\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked\r
[Fri Feb 24 18:44:49.945590 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed\r
[Fri Feb 24 18:44:49.946090 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "<frozen importlib._bootstrap>", line 986, in _gcd_import\r
[Fri Feb 24 18:44:49.946090 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "<frozen importlib._bootstrap>", line 969, in _find_and_load\r
[Fri Feb 24 18:44:49.946090 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965]   File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked\r
[Fri Feb 24 18:44:49.946090 2017] [wsgi:error] [pid 16752:tid 1232] [client ::1:51965] ImportError: No module named 'MainSite'\r

我不完全确定为什么会这样。我试过环顾四周但没找到任何东西。但我认为它与我的wsgi.py文件有关:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MainSite.settings")

application = get_wsgi_application()

这只是默认的wsgi.py文件。我没有找到任何关于配置应该如何的成功。

在我的项目设置中,我有

DEBUG = True

ALLOWED_HOSTS = []

并安装了应用

'mod_wsgi.server',

规格:Apache / 2.4.25(Win64) - mod_wsgi / 4.5.14 - Python / 3.5 - Windows 10

我希望有人可以指导我朝着正确的方向前进。如果我能提供更多信息,请告诉我。

httpd config:

Listen 8080

LoadModule wsgi_module "c:/anaconda3/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win_amd64.pyd"
WSGIPythonHome "c:/anaconda3"

WSGIScriptAlias / C:/Users/Rasmus/workspace/MainSite/src/MainSite/wsgi.py
WSGIPythonPath C:/Users/Rasmus/workspace/MainSite/src/MainSite

<Directory C:/Users/Rasmus/workspace/MainSite/src/MainSite>
  <Files wsgi.py>
    Require all granted
  </Files>
</Directory>

1 个答案:

答案 0 :(得分:1)

使用:

WSGIPythonPath C:/Users/Rasmus/workspace/MainSite/src

你有一个目录太低了。