Reputation: 465
I'm using Django to build a site and I want one part of my site to be in HTTPS.
In my settings.py file, I have
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
In my wsgi.py file, I have os.environ['HTTPS'] = "on"
Then in my views.py for the part of the site I'm working on, I'm using a decorator to force everything to be redirected to https.
def secure_required(view_func):
def _wrapped_view_func(request, *args, **kwargs):
if not request.is_secure():
if getattr(settings, 'HTTPS_SUPPORT', True):
request_url = request.build_absolute_uri(request.get_full_path())
secure_url = request_url.replace('http://', 'https://')
return HttpResponseRedirect(secure_url)
return view_func(request, *args, **kwargs)
return _wrapped_view_func
However, when I try to load the page on my localhost, the page doesn't load and I just get an error that says "This webpage is not available." What am I missing to enable HTTPS for my website?
The webserver log shows this:
13:38:22 web.1 | 2013-08-02 13:38:22 [48421] [CRITICAL] WORKER TIMEOUT (pid:48423)
13:38:22 web.1 | 2013-08-02 13:38:22 [48421] [CRITICAL] WORKER TIMEOUT (pid:48423)
13:38:22 web.1 | 2013-08-02 13:38:22 [48444] [INFO] Booting worker with pid: 48444
Upvotes: 1
Views: 273
Reputation: 465
Turns out https doesn't work on localhost, which I didn't know before.
Upvotes: 1