How to force the use of SSL for some URL of my Django Application?

前端 未结 4 1016
北海茫月
北海茫月 2020-12-08 12:20

I want to be sure that for some URL of my website, SSL will be use. I saw a lot of answer already on SO.

Force redirect to SSL for all pages apart from one

S

4条回答
  •  情话喂你
    2020-12-08 12:50

    If by WSGI you actually mean Apache/mod_wsgi, then although mounted WSGI applications normally get run in their own sub interpreters, the 80/443 split is a special case and even though in different VirtualHost so long as mount point for WSGIScriptAlias, and the ServerName are the same, they will be merged.

    
    ServerName www.example.com
    
    WSGIScriptAlias / /some/path/django.wsgi.
    
    
    
    ServerName www.example.com
    
    WSGIScriptAlias / /some/path/django.wsgi.
    
    

    This will happen for daemon mode as well, but with daemon mode you need to define only a single daemon process group in first VirtualHost definition and then just refer to that from both with WSGIProcessGroup.

    
    ServerName www.example.com
    
    WSGIDaemonProcess mydjangosite ...
    WSGIProcessGroup mydjangosite
    
    WSGIScriptAlias / /some/path/django.wsgi.
    
    
    
    ServerName www.example.com
    
    WSGIProcessGroup mydjangosite
    
    WSGIScriptAlias / /some/path/django.wsgi.
    
    

    The WSGIProcessGroup can only reach across like to that VirtualHost for same ServerName.

    Django provides a is_secure() method for determining when request came via HTTPS which derives from WSGI variable with request called 'wsgi.url_scheme' which is set by mod_wsgi.

    So, you would have one single Django WSGI script file and settings file. You just need to duplicate application mounting as decsribed in Apache/mod_wsgi configuration.

提交回复
热议问题