如何强制使用我的Django应用程序的一些URL的SSL?

我想确保对于我的网站的一些URL,SSL将被使用。 我已经看到了很多答案。

https://stackoverflow.com/questions/724968/force-redirect-to-ssl-for-all-pages-apart-from-one

所以我想我会用mod_rewrite。

我的问题是更多关于如何configuration虚拟主机通过HTTP和HTTPS运行我的Django应用程序没有问题。 我正在使用WSGI。

是否通过*:443和*:80复制configuration是一个问题? 我应该如何做最好的configuration?

谢谢。

雷米

你可以在你的视图上使用装饰器,使它们只能从ssl中获得。

@secure_required @login_required def edit_member(request, slug): ... 

http://www.redrobotstudios.com/blog/2009/02/18/securing-django-with-ssl/

可以复制*:443的configuration,这是我在服务器上做的:

 <VirtualHost *:80> ServerName www.mydomain.tld ServerAlias mydomain.tld DocumentRoot /path/to/www <Directory /path/to/www> AllowOverride All Order allow,deny allow from all Options -MultiViews </Directory> </VirtualHost> <VirtualHost *:443> ServerName www.mydomain.tld ServerAlias mydomain.tld DocumentRoot /path/to/www <Directory /path/to/www> AllowOverride All Order allow,deny allow from all Options -MultiViews </Directory> SSLEngine On SSLCertificateFile /etc/ssl/private/mydomain.crt </VirtualHost> 

请确保在*:443虚拟主机(SSLEngine)上激活SSL,并设置证书(SSLCertificateFile)。

您还需要激活Apache2的ssl模块,以root身份键入:

 a2enmod ssl