0

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?

Nikita
  • 425
  • 1
  • 7
  • 19
  • 1
    The django "runserver" does only handle http at the given server:port combination. What is your target with Apache? do you want in development to serve in parallel http via runserver / https via Apache? Please clarify an post the complete related server definition in httpd.conf including listen, servername, port ... – Razenstein Mar 30 '22 at 08:26
  • @Razenstein: I dont want the app to run over HTTP at all. I want it to run over HTTPS. If possible, I want to take the app into production over HTTPS. I have not specified servername as I am serving my application over ipaddress only with a specific port number. – Nikita Mar 30 '22 at 09:52
  • 1
    did you try apache with https://localhost:443/ ? Could you post the apache startup message when you start apache from comand line with httpd (you then get more celar error message compared to starting in xampp etc.) – Razenstein Mar 30 '22 at 10:17
  • I tried :443 as I have configured in httpd.conf file. But this is just loading forever. And ssl_error_log file is giving: RSA certificate configured for :443 does NOT include an ID which matches the server name. To resolve ssl_error i added ServerName: into httpd.conf but still error is same and :443 is also loading forever. – Nikita Mar 31 '22 at 08:06

0 Answers0