发现了问题。我发生了一个无限循环,并按照此站点进行了修复:
http://yuji.wordpress.com/2008/08/15/django-nginx-making-ssl-work-on-django-behind-a-reverse-proxy/#comment-1941
基本上,将其添加到文件代理位置部分下的 nginx 服务器 conf 设置中:
SECURE_PROXY_SSL_HEADER = (‘HTTP_X_FORWARDED_PROTOCOL’, $scheme)
然后添加到您的 django 设置文件中:
MIDDLEWARE_CLASSES = (...
'djo.middleware.SecureRequiredMiddleware',
)
ROOT_URLCONF = 'djo.urls'
HTTPS_SUPPORT = True
SECURE_REQUIRED_PATHS = (
r'/admin/',
然后在同一个 django 目录中创建一个名为“middleware.py”的文件,其内容如下:
from django.http import HttpResponsePermanentRedirect
from django.conf import settings
class SecureRequiredMiddleware(object):
def __init__(self):
self.paths = getattr(settings, 'SECURE_REQUIRED_PATHS')
self.enabled = self.paths and getattr(settings, 'HTTPS_SUPPORT')
def process_request(self, request):
if self.enabled and not request.is_secure():
for 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
瞧!重定向所需的任何基本 URL。