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
and have the following configuration which I think should do the trick.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin [email protected]
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
<Directory /var/www/my_app_root>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/httpd/conf/ssl/mykey.crt
SSLCertificateKeyFile /etc/httpd/conf/ssl/mykey.key
ServerAdmin [email protected]
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
<Directory /var/www/my_app_root>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
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.
I have a 3rd party php application in the webserver document root /var/www/html/
which works fine over https. Somehow, that application is not facing any issue over http or https.
I tried the following
WSGIProcessGroup
name in both virtual hosts, but that did not work out either. Edit:
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 Listen 443
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.
Do you have both "Listen 80" and "Listen 443" mentioned in your apache2.conf? This might be of some help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With