Python Forum
Trouble deploying Django (project folder, wsgi.py and libapache2-mod-wsgi)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble deploying Django (project folder, wsgi.py and libapache2-mod-wsgi)
#3
Hi @knackwurstbagel!

Thanks for your reply. I took your advice by taking a completely different approach.

I deleted both my remote Django project and local Django project. This time I started a fresh with a new Django project from scratch on my local machine. It runs and behaves beautifully in my development environment. Then I mirrored my new local Django project onto my remote server using rsync.

I changed my apache sites-available ssl configuration file to reflect my new project directory and file names. My new ssl config looks like this:
Quote:<IfModule mod_ssl.c>
<VirtualHost *:443>

ServerAdmin <email>
ServerName daniel496.agency
ServerAlias www.daniel496.agency
# DocumentRoot /var/www/html/daniel496.agency/public_html

# ErrorLog ${APACHE_LOG_DIR}/error.log
ErrorLog ${APACHE_LOG_DIR}/daniel496/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# Django project
Alias /static /home/<user>/TheGreatWork/static
<Directory /home/<user>/TheGreatWork/static>
Require all granted
</Directory>

<Directory /home/<user>/TheGreatWork/TheGreatWork>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

WSGIDaemonProcess TheGreatWork python-home=/home/<user>/TheGreatWork/venv
WSGIProcessGroup TheGreatWork
WSGIScriptAlias / /home/<user>/TheGreatWork/TheGreatWork/wsgi.py

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/daniel496.agency/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/daniel496.agency/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/daniel496.agency/chain.pem

</VirtualHost>
</IfModule>

At this point I’ve ruled out the possibility that the issue has something to do with the Python version 2.7-based libapache2-mod-wsgi because I purged my system of that library. All that exists now is libapache2-mod-wsgi-py3.

My settings.py includes declaration of ALLOWED_HOSTS as [‘daniel496.agency’,’www.daniel496.agency’,]

Here is my site:
https://daniel496.agency/

Still showing:

Quote:Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.

The last 6 lines of my apache error log are as follows:
Quote:[Thu Mar 15 14:54:23.203156 2018] [:error] [pid 17841] [remote 50.101.151.249:20263] mod_wsgi (pid=17841): Target WSGI script '/home/<user>/TheGreatWork/TheGreatWork/wsgi.py' cannot be loaded as Python module.
[Thu Mar 15 14:54:23.203261 2018] [:error] [pid 17841] [remote 50.101.151.249:20263] mod_wsgi (pid=17841): Exception occurred processing WSGI script '/home/<user>/TheGreatWork/TheGreatWork/wsgi.py'.
[Thu Mar 15 14:54:23.203349 2018] [:error] [pid 17841] [remote 50.101.151.249:20263] Traceback (most recent call last):
[Thu Mar 15 14:54:23.203472 2018] [:error] [pid 17841] [remote 50.101.151.249:20263] File "/home/<user>/TheGreatWork/TheGreatWork/wsgi.py", line 12, in <module>
[Thu Mar 15 14:54:23.203492 2018] [:error] [pid 17841] [remote 50.101.151.249:20263] from django.core.wsgi import get_wsgi_application
[Thu Mar 15 14:54:23.203551 2018] [:error] [pid 17841] [remote 50.101.151.249:20263] ImportError: No module named 'django'

So the issue has to do with line 12 of my wsgi.py configuration. Here is wsgi.py and pay particular attention to line 12:

"""
WSGI config for TheGreatWork project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""

import os
import sys
from django.core.wsgi import get_wsgi_application

sys.path.append('/home/<user>/TheGreatWork/TheGreatWork')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "TheGreatWork.settings")

application = get_wsgi_application()
I’m not sure how line 12 could be improved because I only really partially understand what is going on here. All I understand is that line 22 is referring to this file /usr/local/lib/python3.4/dist-packages/django/core/wsgi.py on my system and then from this file, calling the get_wsgi_application function. Here are the complete contents of this small wsgi.py file:

import django
from django.core.handlers.wsgi import WSGIHandler


def get_wsgi_application():
    """
    The public interface to Django's WSGI support. Return a WSGI callable.

    Avoids making django.core.handlers.WSGIHandler a public API, in case the
    internal WSGI implementation changes or moves in the future.
    """
    django.setup(set_prefix=False)
    return WSGIHandler()
I’m lost. The Apache web server error log is pointing to this function inside the wsgi module. What is the problem here? If the Apache error log is referring to wsgi.py as it appears on my root system instead of where it should be, inside my venv, then could the problem be the configuration of my daniel496.agency-le-ssl.conf? I have it listed above and it is not clear to me what the issue is.

I have consulted this guide to help with deploying Django.

Thanks for your attention.
Reply


Messages In This Thread
RE: Trouble deploying Django (project folder, wsgi.py and libapache2-mod-wsgi) - by Drone4four - Mar-15-2018, 07:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  deploying python script on a server rickyrt 0 1,516 Aug-31-2021, 04:03 PM
Last Post: rickyrt
  Django project deployed to Heroku: Postgres security Drone4four 0 1,962 Mar-26-2021, 10:17 AM
Last Post: Drone4four
  creating an exe file for a python django project Sanjish 0 2,659 Dec-27-2020, 07:33 AM
Last Post: Sanjish
  category and subcategory into django project dhirendra007 0 2,040 Dec-26-2020, 10:33 AM
Last Post: dhirendra007
  cant access root environment folder from django folder using __init__.py Sanjish 0 1,949 Dec-25-2020, 05:56 AM
Last Post: Sanjish
  WSGI Multi processing. simbha 1 2,873 May-05-2020, 10:34 AM
Last Post: pyzyx3qwerty
  wsgi server ports chrisdb 3 3,364 Feb-26-2020, 04:24 PM
Last Post: snippsat
  Django project with a setup.py script. That do you think? axju 0 1,664 Oct-22-2019, 10:06 PM
Last Post: axju
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,413 Jun-30-2019, 12:21 AM
Last Post: scidam
  WSGI server vs Web Server chrisdb 24 10,750 May-29-2019, 02:21 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020