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.

SECURE_SSL_REDIRECT = True

so when giving the url in the browser url able to redirect to https://192.168.31.2/cp_vm/details 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 192.168.41.5/cp_vm/details 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
    ServerName 10.206.51.6        

Answers


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
    ServerName 10.206.51.6
    ServerAdmin 10.206.51.6 # <- This should be an email!
    DocumentRoot /dev/null/

    Redirect permanent / https://10.206.51.6/ # Redirects also what is after the "/"
</VirtualHost>


<VirtualHost *:443>
    # SSL site
    ServerName 10.206.51.6
    ServerAdmin 10.206.51.6 # <- 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]
</VirtualHost>

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

Search




Leave an answer