Django | Apache | Deploy website behind SSL

Posted by planet260 on Server Fault See other posts from Server Fault or by planet260
Published on 2014-06-04T12:57:15Z Indexed on 2014/06/04 15:29 UTC
Read the original article Hit count: 220

Filed under:
|
|
|
|

So here are my requirements. I have a website built in Django. I deployed it on Apache Ubuntu. Before there was no SSL involved so the deployment was pretty simple. But now the requirements are changed. Now I have to take a few actions like signup and login behind SSL and present the admin panel and other normally via HTTP. By following the this tutorial I have set-up Apache and SSL and generated certificates for SSL communication. But I am not sure how to proceed, ie. how to serve only a few of my actions through SSL. Below is my configuration. The normal actions are working fine but I don't know how to configure SSL calls.

WSGIScriptAlias / /home/ubuntu/myproject/src/myproject/wsgi.py
WSGIPythonPath /home/ubuntu/myproject/src
<VirtualHost *:80>
    ServerName mydomain.com
    <Directory /home/ubuntu/myproject/src/myproject>
    <Files wsgi.py>
      order deny,allow
      Allow from all
    </Files>
    </Directory>
    Alias /static/admin/ "/home/ubuntu/myproject/src/static/admin/"
    <Directory "/home/ubuntu/myproject/src/static/admin/">
     Order allow,deny
     Options Indexes
     Allow from all
     IndexOptions FancyIndexing
    </Directory>

        <Location "/login">
            RewriteEngine on
            RewriteRule /admin(.*)$ https://mydomain.com/login$1 [L,R=301]
        </Location>
</VirtualHost>

<VirtualHost *:443>
    ServerName mydomain.com
    SSLEngine on
    SSLOptions +StrictRequire
    SSLCertificateFile /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

    <Directory /home/ubuntu/myproject/src/myproject>
    <Files wsgi.py>
      order deny,allow
      Allow from all
    </Files>
    </Directory>
     Alias /static/admin/ "/home/ubuntu/myproject/src/static/admin/"
    <Directory "/home/ubuntu/myproject/src/static/admin/">
     Order allow,deny
     Options Indexes
     Allow from all
     IndexOptions FancyIndexing
    </Directory>
</VirtualHost>

Can you please help me out on how to achieve this? What am I doing wrong? I have read a lot of tutorials but honestly I am not really good at configurations. Any help is appreciated.

© Server Fault or respective owner

Related posts about apache-2.2

Related posts about ssl