Версия 4.5.14 mod_wsgi устарела, используйте последнюю версию.
Предпочтительнее установить ее, используя pip install mod_wsgi
, к вашей установке виртуальной среды Python, поскольку это гарантирует, что будет выбрана правильная общая библиотека Python, котораякогда это не происходит, может вызвать эту проблему.
Затем запустите mod_wsgi-express module-config
, чтобы показать строки конфигурации для добавления в Apache для загрузки mod_wsgi.Сюда также может входить строка LoadFile
для дальнейшего применения правильной библиотеки Python, что важно для Anaconda Python.
Затем используйте конфигурацию:
# I really hope you haven't thrown away your complete Apache
# config file. This should already be defined as part of the
# default Apache config file.
NameVirtualHost *:80
# Put here the output of running mod_wsgi-express module-config.
# Also turn of embedded mode using the following since using
# daemon mode.
WSGIRestrictEmbedded on
# This may not actually be required. Only needed on some RHEL
# and CentOS systems.
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:80>
ServerName xxx.com
DocumentRoot /var/www/html
WSGIScriptReloading On
# The python-path wasn't needed. BTW, don't recommend using pyenv
# if using PSF Python as their default formula for building Python
# from source code doesn't create a shared library so it will not
# work with mod_wsgi. Anaconda Python is probably okay as it would
# use binary distro.
# Ensure python-home is what is value of sys.prefix for Python.
WSGIDaemonProcess xxx python-home=/home/username/.pyenv/versions/anaconda3-5.1.0
WSGIProcessGroup xxx
# Also force main interpreter if have only one app.
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/html/xxx/xxx/wsgi.py
# Apache 2.4 should use 'Require all granted'.
# The ``/xxx`` path should match full absolute directory of WSGI
# script file used in ``WSGIScriptAlias``, so not right here.
<Directory "/xxx/">
Require all granted
</Directory>
</VirtualHost>
Кстати, плохая идеяпоместить исходный код Python в ту же директорию, что и DocumentRoot
.Если вы прокомментируете WSGIScriptAlias
, люди могут загрузить ваш код.