【问题标题】:Deploying Django on Apache with mod_wsgi使用 mod_wsgi 在 Apache 上部署 Django
【发布时间】:2018-06-04 19:14:21
【问题描述】:

我目前正在尝试使用 mod_wsgi 在 Centos 服务器上的 Apache 上设置 Django 应用程序。这设置为在 https 上运行。它在 virtualenv 上。

但是,目前它会给出 504 Gateway Timeout 错误。

错误日志:

(2)No such file or directory: mod_wsgi (pid=15007): Unable to stat Python home /bin/virtualenv:/var/www/django/mysite/mysite/lib/python3.6/site-packages. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

httpd.conf

<VirtualHost *:443>
ServerName mysite.example.com
ServerAlias www.mysite.example.com
# DocumentRoot /var/www/django/mysite

LogLevel info

ErrorLog /etc/httpd/logs/mysite_error.log


Alias /static /var/www/django/mysite/static

<Directory /var/www/django/mysite/static>
  Require all granted
</Directory>

<Directory /var/www/django/mysite/mysite>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

WSGIDaemonProcess mysite python-home=/bin/virtualenv:/var/www/django/mysite/mysite/lib/python3.6/site-packages
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/django/mysite/mysite/wsgi.py
WSGIApplicationGroup %{GLOBAL}


SSLEngine on
SSLProtocol all -SSLv2

SSLCompression off

SSLCertificateFile /etc/pki/tls/certs/mysite.cert.pem
SSLCertificateKeyFile /etc/pki/tls/private/mysite.key.pem
SSLCertificateChainFile /etc/pki/tls/certs/mysite.chain.pem

</VirtualHost>

【问题讨论】:

    标签: django apache centos python-3.6 mod-wsgi


    【解决方案1】:

    这是不正确的:

    WSGIDaemonProcess mysite python-home=/bin/virtualenv:/var/www/django/mysite/mysite/lib/python3.6/site-packages
    

    评论:

    python-home 的值应该是单个目录,这与使用虚拟环境时 Python 的sys.prefix 相同。不要添加site-packages目录。

    最重要的是,mod_wsgi 必须编译为与用于创建虚拟环境相同的 Python 版本。您不能将针对 Python 2.7 编译的 mod_wsgi 与使用 Python 3.6 创建的虚拟环境一起使用。

    检查编译使用的 Python mod_wsgi 版本:

    【讨论】:

    • 这一行确实是问题所在。 python-home 应该是 virtualenv 目录。通过将该行更改为:WSGIDaemonProcess mysite python-home=/var/www/django/mysite
    猜你喜欢
    • 1970-01-01
    • 2012-12-20
    • 2011-07-14
    • 2012-06-17
    • 2012-12-19
    • 2017-01-30
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    相关资源
    最近更新 更多