首页 > 解决方案 > 使用 Apache 部署 Django 2.1 并且 mod_wsgi 提供超时

问题描述

我真的很难让我的 Django-App 2.1 (Python3) 与 Apache2 和 mod_wsgi 一起工作。也许这里的一些好人可以帮助我?

我不得不将我的 80 和 443 的 VHost 放入一个文件中,因为 certbot 只对 VHost 进行复制和粘贴,并且由于需要唯一的 WSGI 进程命名等而导致错误。

所以这是我的 VHost(apache2 configtest 都很好):

 WSGIDaemonProcess my.domain.co processes=2 threads=15 display-name=%{GROUP} python-home=/var/www/site/project/venv/lib/python3.6
 WSGIProcessGroup my.domain.co
 WSGIScriptAlias / /var/www/site/project/wsgi.py
<VirtualHost *:80>
 ServerName my.domain.co
 DocumentRoot /var/www/site

 <directory /var/www/site>
   AllowOverride all
   Require all granted
   Options FollowSymlinks
 </directory>

 Alias /static/ /var/www/site/static/

 <Directory /var/www/site/static>
  Require all granted
 </Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =my.domain.co
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
 ServerName my.domain.co
 DocumentRoot /var/www/site

 <directory /var/www/site>
   AllowOverride all
   Require all granted
   Options FollowSymlinks
 </directory>

 Alias /static/ /var/www/site/project/

 <Directory /var/www/site/static>
  Require all granted
 </Directory>
SSLCertificateFile ...
SSLCertificateKeyFile ...
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

我的项目结构显然在哪里: /var/www/site 作为 venv 所在的主目录,并创建了 django-project。项目目录包含 wsgi.py 和 settings.py。

因此,当我尝试打开我的网站时,我遇到了超时错误。当我在做: python3 manage.py runserver 127.0.0.1:8080 并在其上放置一个反向代理时,它可以工作-但这当然不是它应该如何工作的。

有谁知道我错过了什么?:/

感谢您的帮助,非常感谢!

编辑:

日志:

Current thread 0x00007f8064915bc0 (most recent call first):
[Sun Oct 14 06:28:55.988638 2018] [core:notice] [pid 47497] AH00051: child pid 36608 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

错误:

524

标签: pythondjangoapache2mod-wsgi

解决方案


推荐阅读