Take Django application to https using apache and mod_wsgi on RHEL7

21 views
Skip to first unread message

Nikita Gupta

unread,
Mar 25, 2022, 7:17:21 AMMar 25
to modwsgi
Hi,

I read in django document that "Deploying Django with Apache and mod_wsgi is a tried and tested way to get Django into production."

Hence I started with this combination. My Django application is working perfectly fine on http://localhost:8081.
But my requirement is to take it to https://locahost:8081.

I have installed apache and mod_wsgi on RHEL7 machine. and modified the configuration of Apache wrt mod_wsgi as:
LoadModule wsgi_module modules/mod_wsgi.so WSGIScriptAlias / /path/to/django/app/wsgi.py WSGIPythonHome /home/user/python3.9 WSGIPythonPath "/home/user/python3.9/lib;/home/user/python3.9/lib/python3.9/site-packages" <Directory /path/to/django/app> <Files wsgi.py> Require all granted </Files> </Directory>

Restarted the httpd service.

Now what should be next step to take it to https? Any suggestions?

Regards,
Nikita

Graham Dumpleton

unread,
Mar 25, 2022, 7:34:17 AMMar 25
to mod...@googlegroups.com

On 25 Mar 2022, at 10:10 pm, Nikita Gupta <nikit...@gmail.com> wrote:

Hi,

I read in django document that "Deploying Django with Apache and mod_wsgi is a tried and tested way to get Django into production."

Hence I started with this combination. My Django application is working perfectly fine on http://localhost:8081.
But my requirement is to take it to https://locahost:8081.

I have installed apache and mod_wsgi on RHEL7 machine. and modified the configuration of Apache wrt mod_wsgi as:

You can't just copy the configuration from the Django documentation exactly as is, it would need to be customised to your specific setup and requirements. You have also set some values incorrectly.

LoadModule wsgi_module modules/mod_wsgi.so

How was mod_wsgi installed? If a system package, is Python 3.9 also what your system packages provide? It is required that mod_wsgi be compiled with the same Python version you intend using.

WSGIScriptAlias / /path/to/django/app/wsgi.py

What is the real path to your wsgi.py file?

WSGIPythonHome /home/user/python3.9

Are you actually using a Python virtual environment? What is the real path to the root of it?

See:


for details on what you should be setting WSGIPythonHome to if using a Python virtual environment.

WSGIPythonPath "/home/user/python3.9/lib;/home/user/python3.9/lib/python3.9/site-packages"

This is incorrect. You do not need to add lib/site-packages of your Python installation or virtual environment to WSGIPythonPath. On UNIX systems even if you had to list multiple directories, the path separator is a colon, not a semi colon.

What WSGIPythonPath should be set it if using Django is the parent directory of your Django project.

<Directory /path/to/django/app>

This should be the path to the directory containing the wsgi.py file from Django.

<Files wsgi.py>
Require all granted
</Files>
</Directory>

Restarted the httpd service.

Now what should be next step to take it to https? Any suggestions?

Can you provide the configuration with the actual paths you used if what you showed isn't what you used? If this is what you used, what are the real paths to any virtual environment used and your Django project?

If you didn't actually provide what you really used and Apache did actually start up, what happened when you tried to access the site and what errors were there in the Apache error log?

Given that Apache usually listens on port 80, what did you do to set up a VirtualHost for port 81 and where did you put all the mod_wsgi configuration relative to that VirtualHost?

Graham

Reply all
Reply to author
Forward
0 new messages