Apache + Django + WSGI:页面不工作

Apache + Django + WSGI : Page is not working

我不明白为什么我的 Apache 服务器不工作。当我尝试使用 Opera 连接到地址 http://bde.yggdrasil.cafe 时,我收到以下消息 This page isn't working bde.yggdrasil.cafe is currently unable to handle this request. 我不明白为什么。

我在 /etc/httpd/conf/http.conf

中启用 mod_wsgi

这是我在主配置中导入的配置文件:

$ cat  /etc/httpd/conf/extra/bdeweb.conf
<VirtualHost *:80>
    # This is name based virtual hosting. So place an appropriate server name
    #   here. Example: django.devsrv.local
    ServerName  bde.yggdrasil.cafe
    ServerAdmin     my@email.fr
    DocumentRoot    /srv/http/bdeweb

    # This alias makes serving static files possible.
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    Alias /static/  /hdd/bdeweb/static

    # This alias makes serving media files possible.
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    Alias /media/   /srv/http/bdeweb/media

    # Insert the full path to the wsgi.py-file here
    WSGIScriptAlias /   /srv/http/bdeweb/bdewebsite/wsgi.py



    # PROCESS_NAME specifies a distinct name of this process
    #   see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess
    # PATH/TO/PROJECT_ROOT is the full path to your project's root directory, 
    #   containing your project files
    # PATH/TO/VIRTUALENV/ROOT: If you are using a virtualenv specify the full
    #   path to its directory.
    #   Generally you must specify the path to Python's site-packages.
    #WSGIDaemonProcess   bdewebsite  python-path=/srv/http/bdeweb python-home=/usr/bin/python3

    # PROCESS_GROUP specifies a distinct name for the process group
    #   see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIProcessGroup
    WSGIProcessGroup     bdewebsite

    <Directory /srv/http/bdeweb/bdewebsite>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    # Serving static files from this directory
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    <Directory /hdd/bdeweb/static>
        Require all granted
    </Directory>

    # Serving media files from this directory
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    <Directory /srv/http/bdeweb/media>
        Require all granted
    </Directory>

    LogLevel debug

    # PROJECT_NAME is used to seperate the log files of this application
    ErrorLog    ${APACHE_LOG_DIR}/bdeweb_error.log
    CustomLog   ${APACHE_LOG_DIR}/bdeweb_access.log combined
</VirtualHost>

我的服务器启动良好,没有错误:

$ sudo systemctl restart httpd && systemctl -l status httpd
* httpd.service - Apache Web Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-10-31 10:55:38 UTC; 51ms ago
  Process: 11938 ExecStop=/usr/bin/httpd -k graceful-stop (code=exited, status=0/SUCCESS)
 Main PID: 11943 (httpd)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/httpd.service
           `-11943 /usr/bin/httpd -k start -DFOREGROUND

Oct 31 10:55:38 Yggdrasil systemd[1]: Started Apache Web Server.

我在 journactl 中没有错误:

$ journalctl -xe
[...]
-- Subject: Unit httpd.service has begun shutting down
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit httpd.service has begun shutting down.
Oct 31 10:55:38 Yggdrasil systemd[1]: httpd.service: Killing process 11851 (httpd) with signal SIGKILL.
Oct 31 10:55:38 Yggdrasil systemd[1]: httpd.service: Killing process 11852 (httpd) with signal SIGKILL.
Oct 31 10:55:38 Yggdrasil systemd[1]: httpd.service: Killing process 11853 (httpd) with signal SIGKILL.
Oct 31 10:55:38 Yggdrasil systemd[1]: httpd.service: Killing process 11854 (httpd) with signal SIGKILL.
Oct 31 10:55:38 Yggdrasil systemd[1]: httpd.service: Killing process 11855 (httpd) with signal SIGKILL.
Oct 31 10:55:38 Yggdrasil systemd[1]: httpd.service: Killing process 11908 (httpd) with signal SIGKILL.
Oct 31 10:55:38 Yggdrasil systemd[1]: Stopped Apache Web Server.
-- Subject: Unit httpd.service has finished shutting down
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit httpd.service has finished shutting down.
Oct 31 10:55:38 Yggdrasil systemd[1]: Started Apache Web Server.
-- Subject: Unit httpd.service has finished start-up
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit httpd.service has finished starting up.
-- 
-- The start-up result is RESULT.
Oct 31 10:55:38 Yggdrasil sudo[11935]: pam_unix(sudo:session): session closed for user root

编辑 1:我的错误日志也是空的:

$ cat /var/log/httpd/bdeweb_error.log
$

编辑 2:如果我取消注释行 WSGIDaemonProcess 我在 apache 错误日志中有以下错误:

 mod_wsgi (pid=12450): Target WSGI script '/srv/http/bdeweb/bdewebsite/wsgi.py' cannot be loaded as Python module.
 mod_wsgi (pid=12450): Exception occurred processing WSGI script '/srv/http/bdeweb/bdewebsite/wsgi.py'.
 Traceback (most recent call last):
   File "/srv/http/bdeweb/bdewebsite/wsgi.py", line 16, in <module>
     application = get_wsgi_application()
   File "/usr/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
     django.setup(set_prefix=False)
   File "/usr/lib/python3.6/site-packages/django/__init__.py", line 22, in setup
     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
   File "/usr/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
     self._setup(name)
   File "/usr/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
     self._wrapped = Settings(settings_module)
   File "/usr/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
     mod = importlib.import_module(self.SETTINGS_MODULE)
   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 978, in _gcd_import
   File "<frozen importlib._bootstrap>", line 961, in _find_and_load
   File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
   File "<frozen importlib._bootstrap>", line 978, in _gcd_import
   File "<frozen importlib._bootstrap>", line 961, in _find_and_load
   File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
 ModuleNotFoundError: No module named 'bdewebsite'

我做错了什么?

解决方案

我不得不从 WSGIDaemonProcess 中删除 python-home=/usr/bin/python3 并且我更改了进程组的名称。

解决方案

我不得不删除 python-home=/usr/bin/python3from WSGIDaemonProcess 并且更改了进程组的名称。