title: How to use SSL with Django app (deployed using mod_wsgi and virtualenv)
body: <p>Disclaimer: I don't really know what I'm doing, so I may have phrased things wrong. I've also never asked/answered a question on here before!</p>
  
  <p>I have a Django app running on Apache that I deployed using mod_wsgi and virtualenv. I want some parts of the app to use SSL, however when I install the SSL certificate, the https URL goes to the index.html file from my public_html folder instead of the app (which is outside of public_html) </p>
  
  <p>For example, visit <a href="https://tradekandi.com">https://tradekandi.com</a>. That URL is just a basic HTML file: public_html/index.html
  Then visit <a href="http://tradekandi.com">http://tradekandi.com</a>. That's my Django page (in maintenance mode).</p>
  
  <p>I've searched stackoverflow and Google all day. I've tried removing the documentroot from the virtual hosts file but that did nothing. I tried adding a SetEnvIf X-Forwarded-Proto https HTTPS=1 line to it but that did nothing either. </p>
  
  <p>My virtual hosts file has these lines in it:</p>
  
  <pre><code>SSLEngine on 
  SSLCertificateFile /etc/ssl/certs/tradekandi.com.crt
  SSLCertificateKeyFile /etc/ssl/private/tradekandi.com.key
  SSLCACertificateFile /etc/ssl/certs/tradekandi.com.cabundle
  </code></pre>
  
  <p>Whenever I make any changes, I restart apache and "touch" the app's wsgi file.</p>
  
  <p>How can I make the https URL load the Django app? Any help would be much appreciated. Thank you.</p>
  
  <p>More of httpd configuration:</p>
  
  <pre><code>&lt;VirtualHost 69.65.42.153:80&gt;
  ServerName tradekandi.com
  ServerAlias www.tradekandi.com
  DocumentRoot /home/trade/public_html
  ServerAdmin webmaster@tradekandi.com
  UseCanonicalName Off
  CustomLog /usr/local/apache/domlogs/tradekandi.com combined
  CustomLog /usr/local/apache/domlogs/tradekandi.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
  ## User trade # Needed for Cpanel::ApacheConf
  &lt;IfModule mod_suphp.c&gt;
      suPHP_UserGroup trade trade
  &lt;/IfModule&gt;
  &lt;IfModule !mod_disable_suexec.c&gt;
      SuexecUserGroup trade trade
  &lt;/IfModule&gt;
  ScriptAlias /cgi-bin/ /home/trade/public_html/cgi-bin/
  
  Include "/usr/local/apache/conf/userdata/*.conf"  
  Include "/usr/local/apache/conf/userdata/*.owner-root" 
  Include "/usr/local/apache/conf/userdata/std/*.conf" 
  Include "/usr/local/apache/conf/userdata/std/*.owner-root" 
  Include "/usr/local/apache/conf/userdata/std/2/*.conf" 
  Include "/usr/local/apache/conf/userdata/std/2/*.owner-root" 
  Include "/usr/local/apache/conf/userdata/std/2/trade/*.conf"  
  Include "/usr/local/apache/conf/userdata/std/2/trade/tradekandi.com/*.conf"
  
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost 69.65.42.153:443&gt;
  ServerName tradekandi.com
  ServerAlias www.tradekandi.com
  DocumentRoot /home/trade/public_html
  ServerAdmin webmaster@tradekandi.com
  UseCanonicalName Off
  CustomLog /usr/local/apache/domlogs/tradekandi.com combined
  CustomLog /usr/local/apache/domlogs/tradekandi.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
  ## User nobody # Needed for Cpanel::ApacheConf
  &lt;IfModule mod_suphp.c&gt;
      suPHP_UserGroup nobody nobody
  &lt;/IfModule&gt;
  ScriptAlias /cgi-bin/ /home/trade/public_html/cgi-bin/
  SSLEngine on
  
  SSLCertificateFile /etc/ssl/certs/tradekandi.com.crt
  SSLCertificateKeyFile /etc/ssl/private/tradekandi.com.key
  SSLCACertificateFile /etc/ssl/certs/tradekandi.com.cabundle
  CustomLog /usr/local/apache/domlogs/tradekandi.com-ssl_log combined
  SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
  &lt;Directory "/home/trade/public_html/cgi-bin"&gt;
      SSLOptions +StdEnvVars
  &lt;/Directory&gt;
  Include "/usr/local/apache/conf/userdata/*.conf"
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>If it's relevant, this is a dedicated server running CentOS &amp; I am also using it to host one PHP-based site.</p>
  
  <p>Wsgi file:</p>
  
  <pre><code>import os
  import sys
  sys.stdout = sys.stderr
  
  from os.path import abspath, dirname, join
  from site import addsitedir
  sys.path.append('/home/trade/sites/tradekandi.com.env/lib/python2.7/site-packages')
  sys.path.insert(0, abspath(join(dirname(__file__), "../../")))
  
  from django.conf import settings
  os.environ["DJANGO_SETTINGS_MODULE"] = "trade.settings"
  
  sys.path.insert(0, join(settings.PROJECT_ROOT, "apps"))
  
  from django.core.handlers.wsgi import WSGIHandler
  application = WSGIHandler()
  </code></pre>
  
  <p>extra.conf with mod_wsgi directives:</p>
  
  <pre><code>Alias /static/ /home/trade/public_html/static/
  
  &lt;Directory /home/trade/public_html/static&gt;
  Order deny,allow
  Allow from all
  &lt;/Directory&gt;
  
  WSGIDaemonProcess trade python-path=/home/trade/sites/tradekandi.com.env/lib/python2.7/site-packages
  WSGIProcessGroup trade
  
  WSGIScriptAlias / /home/trade/sites/tradekandi.com.env/site/trade/deploy/pinax.wsgi
  
  &lt;Directory /home/trade/sites/tradekandi.com.env/site/trade/deploy&gt;
  Order deny,allow
  Allow from all
  &lt;/Directory&gt;
  </code></pre>