Force HTTPS in Nginx for Django -


i have tried this:

  1. create file named middleware.py (chmod 775, chown www-data) in same directory settings.py
  2. paste in middleware.py: http://djangosnippets.org/snippets/880/
  3. paste in settings.py:

    middleware_classes = ( #...     'djo.middleware.sslredirect', )  ssl_enabled = true ssl_urls = (     r'/admin/', ) 

i get: internal server error

no errors in development server shown.

suggestions?

found problem. had infinite loop happening , followed site fix it:

http://yuji.wordpress.com/2008/08/15/django-nginx-making-ssl-work-on-django-behind-a-reverse-proxy/#comment-1941

basically, add nginx server conf setting under proxy location part of file:

secure_proxy_ssl_header = (‘http_x_forwarded_protocol’, $scheme) 

then add django settings file:

middleware_classes = (... 'djo.middleware.securerequiredmiddleware', )  root_urlconf = 'djo.urls'  https_support = true secure_required_paths = (     r'/admin/', 

then create file in same django directory called "middleware.py" following contents:

from django.http import httpresponsepermanentredirect django.conf import settings class securerequiredmiddleware(object):     def __init__(self):         self.paths = getattr(settings, 'secure_required_paths')         self.enabled = self.paths , getattr(settings, 'https_support')      def process_request(self, request):         if self.enabled , not request.is_secure():             path in self.paths:                 if request.get_full_path().startswith(path):                     request_url = request.build_absolute_uri(request.get_full_path())                     secure_url = request_url.replace('http://', 'https://')                     print self.paths, request_url, secure_url                     return httpresponsepermanentredirect(secure_url)         return none 

voilá! redirects base url desired.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -