1 year ago

#352788

test-img

Nikita

django not functioning over HTTPS with apache and mod_wsgi

My requirement is to take my django app over HTTPS.

I generated ssl certs with the help of command:

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout ssl_cert.key -out ssl_cert.crt

Installed mod_wsgi and mod_ssl and configured them into httpd.conf as:

SSLCertificateChainFile "location/to/certs/ssl_cert.cert"
WSGIScriptAlias / /location/to/django/app/wsgi.py
WSGIPythonHome /root/python3.9
#WSGIPythonPath "/root/python3.9/lib;/root/python3.9/lib/python3.9/site-packages"
WSGIPythonPath /location/to/django/app

<Directory /location/to/django/app>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

And restarted apache service.

I made changes in settings.py as:

SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

Now on starting Django App with command:

HTTPS=on python3 manage.py runserver 8000

It says:

Django version 2.2, using settings 'djangoApp.settings'
Starting development server at http://localhost:8000/

And its still accessible over http only and if trying to access over HTTPS, it gives error as:

This site can’t provide a secure connection

from debug.log:

You're accessing the development server over HTTPS, but it only supports HTTP.

Can somebody please help what I'm missing to configure and how to solve this issue?

django

apache

https

mod-wsgi

mod-ssl

0 Answers

Your Answer

Accepted video resources