I have a django application and I would like to apply SSL to the admin pages. Since the admin page are the only pages needing SSL I want to do this using the apache configuration files and not using SSLMiddleware. My (partial) apache configuration files look like this:
<VirtualHost *:80>
.
.
DocumentRoot /home/www/sites_django/wmssite
.
<Directory "/home/www/sites_django/wmssite">
.
</Directory>
<Location "/admin">
RewriteEngine On
RewriteRule ^/(.*) https://www.whitemoorstudio.pvm/admin [L,R=301]
</Location>
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/usr/local/etc/apache22/www_whitemoorstudio_pvm.crt"
SSLCertificateKeyFile "/usr/local/etc/apache22/www_whitemoorstudio_pvm.key"
.
.
</VirtualHost>
The TLD .pvm is a local TLD I just use for testing on my internal network.
I have set up a self-sgned certificate and it works, well.... sort of. The strange thing is that for some reason when rewriting to https it cannot find the media files in the /media directory, no images, no css, no js. The apache error log tells me it is looking in the directory /usr/local/www/apache22/data/media:
开发者_JAVA百科[Sat Nov 06 20:45:18 2010] [error] [client 192.168.1.134] File does not exist: /usr/local/www/apache22/data/media, referer: https://www.whitemoorstudio.pvm/admin/
When I don't rewrite to https the admin media directory /usr/local/www/apache22/media. This directory media is a logical link:
media -> /usr/local/lib/python2.5/site-packages/django/contrib/admin/media
I have no idea why without SSL it is looking in:
/usr/local/www/apache22/media
and with SSL in:
/usr/local/www/apache22/data/media
This last directory doesn't exist!!!
Anyone any idea?
Problem already solved. When adding the stuff in the VirtualHost *:443 container
I had forgotten to specify the DocumentRoot directive so it was as specified in the main httpd.conf.
It went well in the VirtualHost *:80 container because in that section I had specified DocumentRoot.
In httpd.conf it is specified as: DocumentRoot "/usr/local/www/apache22/data"
精彩评论