Enable AWS ELB with SSL Termination

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from django import http

class CloudMiddleware(object):
    def process_request(self, request):
        if 'HTTP_X_FORWARDED_PROTO' in request.META:
            if request.META['HTTP_X_FORWARDED_PROTO'] == 'https':
                request.is_secure = lambda: True
                return None

        host = request.get_host()
        if host.find('example.com') >= 0:
            new_url = 'https://%s%s' % (host, request.get_full_path())
            return http.HttpResponsePermanentRedirect(new_url)

        return None

More like this

  1. SSL Middleware by sjzabel 6 years, 2 months ago
  2. WebFaction fixes middleware by spookylukey 3 years, 8 months ago
  3. SSL Middleware for Webfaction by parlar 6 years ago
  4. TLS(SSL) middleware, per URL pattern or whole site by robmadole 2 years, 5 months ago
  5. Get Client IP Behind Proxy by brianjaystanley 1 year, 7 months ago

Comments

(Forgotten your password?)