Deploying Django on Apache with mod_wsgi
我目前正在尝试使用mod_wsgi在Centos服务器上的Apache上设置Django应用程序。 设置为在https上运行。 它在virtualenv上。
但是,当前它给出了504网关超时错误。
错误日志:
1 2 3 | (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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <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> |
这是不正确的:
1 | WSGIDaemonProcess mysite python-home=/bin/virtualenv:/var/www/django/mysite/mysite/lib/python3.6/site-packages |
评论:
- http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
最重要的是,必须为mod_wsgi编译与用于创建虚拟环境的Python版本相同的Python版本。 您不能在Python 3.6创建的虚拟环境中使用针对Python 2.7编译的mod_wsgi。
检查编译使用的Python mod_wsgi版本:
- http://modwsgi.readthedocs.io/zh-CN/develop/user-guides/checking-your-installation.html#python-installation-in-use