Home Ask Login Register

Developers Planet

Your answer is one click away!

arun February 2016

how to configure django on apache and make https in the apache so that django url should open with https://<ip>:80 port

I want to get django to run on https server securely without using thirdparty packages like runsslserver, or sslserver for that i was this approach

in the settings.py file i have configured these line.


so when giving the url in the browser url able to redirect to but i'm getting secure ssl error.

please suggest me any ways to get the output, or running the django on apache with https also fine but i'm able to find the links https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04 but after that giving the ip in the browser it shows unable to connect.

i'm attaching the apache 000.default.conf file also please help me in this, Pleas forgive me if any mistakes in the above kindly suggest me some pointers so that

  1. I can run django on apache server first .
  2. Then getting the https// on the same apache server. please provide me some help would be great if any helping hands.

My config file as follows:

<VirtualHost *:80>

    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com


Tony February 2016

On top of the HTTP server, you need to run an SSL server with Apache2, i.e. configure a <VirtualHost *:443>. Also, I would let Apache2 handle the redirection instead of Django.

<VirtualHost *:80>
    # Virtual host for the redirection
    ServerAdmin # <- This should be an email!
    DocumentRoot /dev/null/

    Redirect permanent / # Redirects also what is after the "/"

<VirtualHost *:443>
    # SSL site
    ServerAdmin # <- This should be an email!
    DocumentRoot /var/www/nfvs_portal/

    SSLCertificateFile /etc/apache2/certs/your-server-certificate.pem
    SSLCertificateKeyFile /etc/apache2/certs/your-server-certificate.key.pem

    # ... [The rest of your site configuration]

If you get into trouble even with this configuration, I would split the problem in (1) making Apache2 manage to redirect and serve a static SSL page in your document root (without using WSGI), and (2) modify that configuration to use your Django site.

Post Status

Asked in February 2016
Viewed 2,197 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life