title: SSL based virtual host with django and mod_wsgi
body: <p>I have a django web application in which some URLs are allowed to be accessed over http while others have to be over http-secure only. I need to set up the virtualHost/ mod_wsgi configuration in my apache conf file, so that the same web application can be accessed over both. I followed these 2 posts</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1548210/how-to-force-the-use-of-ssl-for-some-url-of-my-django-application">How to force the use of SSL for some URL of my Django Application?</a></li>
  <li><a href="https://stackoverflow.com/questions/2131727/django-and-ssl-question">Django and SSL question</a></li>
  </ul>
  
  <p>and have the following configuration which I think should do the trick.</p>
  
  <pre><code>NameVirtualHost *:80
  &lt;VirtualHost *:80&gt;
      ServerAdmin me@mail.com
      DocumentRoot /var/www/html
      ServerName www.mydomain.com
  
      ErrorLog server-logs/error_log
      CustomLog server-logs/access_log common
  
      WSGIScriptAlias /test /var/www/my_app_root/apache/django.wsgi
  
      &lt;Directory /var/www/my_app_root&gt;
        Order allow,deny
        Allow from all
      &lt;/Directory&gt;    
  &lt;/VirtualHost&gt;
  
  NameVirtualHost *:443
  &lt;VirtualHost *:443&gt;
      SSLEngine On
      SSLCertificateFile /etc/httpd/conf/ssl/mykey.crt
      SSLCertificateKeyFile /etc/httpd/conf/ssl/mykey.key
  
      ServerAdmin me@mail.com
      DocumentRoot /var/www/html
      ServerName www.mydomain.com
  
      ErrorLog server-logs/error_log
      CustomLog server-logs/access_log common
  
      WSGIScriptAlias /test /var/www/my_app_root/apache/django.wsgi
  
      &lt;Directory /var/www/my_app_root&gt;
        Order allow,deny
        Allow from all
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>However, the urls which have to be accessed over http are being accessed without any issues, while those which have to be over https are getting a 404 - not found error.
  I have a decorator which sees if a view is being accessed over http and then redirects to a url with the http replaced by https. So the url-mapping is correct since I see the redirect happening (that means the view gets called) but over https, it gets 404 error.</p>
  
  <p>I have a 3rd party php application in the webserver document root <code>/var/www/html/</code> which works fine over https. Somehow, that application is not facing any issue over http or https.</p>
  
  <p>I tried the following </p>
  
  <ul>
  <li>Tried the Daemon mode approach with the same <code>WSGIProcessGroup</code> name in both virtual hosts, but that did not work out either. </li>
  <li>I tried adding Listen 443 command, and apache complained of a port already bound error.</li>
  </ul>
  
  <p>Edit:</p>
  
  <p>Due to all your comments, I explored the configurations a bit more and found that there was a sub conf file which was getting pulled in at run time which was defining the *:443 virtual host (and did not have the wsgiscript directive). That's why the <code>Listen 443</code> was throwing an error. And that also explains the 404 for the url over https (the virtualhost handling *:443 was unable to resolve that url). Now I modified it and everything is working fine. The approaches suggested in the 2 stack overflow posts in my original question are perfect and work correctly. </p>