WSGI не находит модули Python
Попытка запустить сервер Django с Apache и WSGI
Это мой wsgi.py
import os
from django.core.wsgi import get_wsgi_application
sys.path.append('/home/rohan/Desktop/narsil/narsil')
# adjust the Python version in the line below as needed
sys.path.append('/home/rohan/Desktop/narsil/narsilenv/lib/python3.6')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "narsil.settings")
application = get_wsgi_application()
А это мой файл /etc/apache2/sites-enabled
<VirtualHost *:80>
ServerName narsil.mti.local
DocumentRoot /home/rohan/Desktop/narsil
WSGIScriptAlias / /home/rohan/Desktop/narsil/narsil/wsgi.py
# adjust the following line to match your Python path
WSGIDaemonProcess narsil.mti.local processes=2 threads=15 display-name=%{GROUP} python-home=/home/rohan/Desktop/narsil/narsilenv/lib/python3.6/site-packages
WSGIProcessGroup narsil.mti.local
<directory /home/rohan/Desktop/narsil>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/rohan/Desktop/narsil/static/
<Directory /home/rohan/Desktop/rohan/static>
Require all granted
</Directory>
</VirtualHost>
Это из журнала ошибок
Current thread 0x00007f0d45637bc0 (most recent call first):
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Я пробовал подобные решения, упомянутые здесь, но они, кажется, не работают. Я использую virtualenv с установкой pip mod_wsgi. Django возвращается 404 Not Found Это журнал от apachectl -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80 is a NameVirtualHost
default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost narsil.mti.local (/etc/apache2/sites-enabled/narsil.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
1 ответ
Может быть, ваша проблема только в том, что вы написали
WSGIDaemonProcess narsil.mti.local processes=2 threads=15 display-name=%{GROUP} python-home=/home/rohan/Desktop/narsil/narsilenv/lib/python3.6/site-packages
вместо
WSGIDaemonProcess narsil.mti.local processes=2 threads=15 display-name=%{GROUP} python-path=/home/rohan/Desktop/narsil:/home/rohan/Desktop/narsil/narsilenv/lib/python3.6/site-packages
(две разницы, это python-path, а не home, и я также добавляю в путь корневую папку вашего кода)
К вашему сведению, это мой site.conf Обратите внимание, что я не использую virtualenv, я запускаю один проект в контейнере Docker.
LoadModule wsgi_module /usr/local/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
WSGIRestrictEmbedded On
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/${CERT_NAME}.crt
SSLCertificateKeyFile /etc/apache2/ssl/${CERT_NAME}.key
ServerAdmin no-reply@localhost
DocumentRoot /var/www/html
WSGIScriptAlias / /code/${PROJECT_NAME}/wsgi.py process-group=bdchem_project
WSGIDaemonProcess bdchem_project python-path=/code:/usr/local/lib/python3.6/site-packages
WSGIProcessGroup bdchem_project
Alias ${STATIC_URL}/ /code/.static/
Alias ${MEDIA_URL}/ /code/.media/
Alias /favicon.ico /code/.static/favicon.ico
Alias /robots.txt /code/.static/robots.txt
Redirect permanent "/apple-touch-icon-precomposed.png" "${STATIC_URL}/favicon-256.png"
Redirect permanent "/apple-touch-icon.png" "${STATIC_URL}/favicon-256.png"
<Directory /code/${PROJECT_NAME}>
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Require all granted
</Directory>
<Directory /code/.static>
Require all granted
</Directory>
<Directory /code/.media>
Require all granted
</Directory>
<Location />
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/js "access plus 1 year"
ExpiresByType text/x-javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType text/csv "access plus 0 seconds"
#ExpiresByType application/ld json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType text/html "access plus 0 seconds"
ExpiresDefault "access plus 1 day"
</Location>
</VirtualHost>