3

Trying to get Django server running with Apache and WSGI

This is my 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() 

And this is my /etc/apache2/sites-enabled conf file

<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> 

This is from the error log

Current thread 0x00007f0d45637bc0 (most recent call first): Fatal Python error: Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No module named 'encodings' 

I tried the similar solutions mentioned here but they dont seem to work. I am using virtualenv with pip install mod_wsgi. The Django is returning 404 Not Found This is the log from 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 Answer 1

2

Maybe your problem is only that you written

WSGIDaemonProcess narsil.mti.local processes=2 threads=15 display-name=%{GROUP} python-home=/home/rohan/Desktop/narsil/narsilenv/lib/python3.6/site-packages 

instead of

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 

(two difference, it is python-path not home, and I also add in the path the root folder of your code)

FYI here is my site.conf Note that I do not use a virtualenv, i run a single project in a docker container

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> 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.