gpt4 book ai didi

Webfaction 上的 Django SSLMiddleware 问题

转载 作者:太空宇宙 更新时间:2023-11-03 15:06:06 24 4
gpt4 key购买 nike

我在 Linode 上使用以下 SSLMiddleware 有一段时间了,我的 SSL 在这方面工作得很好,现在我已经将我的服务器更改为 Webfaction,突然之间,我的 HTTPS 页面无法正常工作它被正确地重定向到https页面,但是我所有的css文件,css文件中的图像(没有绝对url),javascript都变成了不安全的来源(指的是http://而不是https://),我真的现在很困惑,因为我不知道它是否与 SSLMiddleware 或其他东西有关,除了数据库参数值之外,我没有更改 settings.py 中的任何内容。请帮助。提前致谢。

__license__ = "Python"
__copyright__ = "Copyright (C) 2007, Stephen Zabel"
__author__ = "Stephen Zabel - sjzabel@gmail.com"
__contributors__ = "Jay Parlar - parlar@gmail.com"

from django.conf import settings
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect, get_host

SSL = 'SSL'

class SSLRedirect:

def process_view(self, request, view_func, view_args, view_kwargs):
if SSL in view_kwargs:
secure = view_kwargs[SSL]
del view_kwargs[SSL]
else:
secure = False

if settings.ENABLE_SSL:
if not secure == self._is_secure(request):
return self._redirect(request, secure)
else:
return

def _is_secure(self, request):
if request.is_secure():
return True

#Handle the Webfaction case until this gets resolved in the request.is_secure()
if 'HTTP_X_FORWARDED_SSL' in request.META:
return request.META['HTTP_X_FORWARDED_SSL'] == 'on'

return False

def _redirect(self, request, secure):
protocol = secure and "https" or "http"
newurl = "%s://%s%s" % (protocol,get_host(request),request.get_full_path())
if settings.DEBUG and request.method == 'POST':
raise RuntimeError, \
"""Django can't perform a SSL redirect while maintaining POST data.
Please structure your views so that redirects only occur during GETs."""

return HttpResponsePermanentRedirect(newurl)

最佳答案

我最近在没有任何自定义中间件修补的情况下在 WebFaction 上实现了 SSL,这是一个非常简单的过程。

看看这里:http://community.webfaction.com/questions/512/how-do-i-set-up-a-https-ssl-django-site

如果这没有帮助,请向他们开票。他们通常非常擅长快速解决问题。

关于Webfaction 上的 Django SSLMiddleware 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8492324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com