Different settings for secure & non-secure versions of Django site using WSGI

Posted by Jordan Reiter on Server Fault See other posts from Server Fault or by Jordan Reiter
Published on 2012-09-14T16:57:07Z Indexed on 2012/09/15 9:40 UTC
Read the original article Hit count: 374

Filed under:
|
|

I have a Django website where some of the URLs need to be served over HTTPS and some over a normal connection.

It's running on Apache and using WSGI. Here's the config:

<VirtualHost example.org:80>
    ServerName example.org
    DocumentRoot /var/www/html/mysite

    WSGIDaemonProcess mysite
    WSGIProcessGroup mysite

    WSGIScriptAlias / /path/to/mysite/conferencemanager.wsgi    
</VirtualHost>

<VirtualHost *:443>
    ServerName example.org
    DocumentRoot /var/www/html/mysite

    WSGIProcessGroup mysite

    SSLEngine on
    SSLCertificateFile /etc/httpd/certs/aace.org.crt
    SSLCertificateKeyFile /etc/httpd/certs/aace.org.key
    SSLCertificateChainFile /etc/httpd/certs/gd_bundle.crt

    WSGIScriptAlias / /path/to/mysite/conferencemanager_secure.wsgi     
</VirtualHost>

When I restart the server, the first site that gets called -- https or http -- appears to select which WSGI script alias gets used.

I just need a few settings to be different for the secure server, which is why I'm using a different WSGI script. Alternatively, it there's a way to change settings in the settings.py file based on whether the connection is secure or not, that would also work.

Thanks

© Server Fault or respective owner

Related posts about ssl

Related posts about django