python - Heroku 仍然重定向到 https

标签 python django ssl heroku https

我几天前从我们的站点中删除了 SSL,但遇到了很多问题。然而,大多数问题都已解决,只有一个存在:即使您输入了 http,也会被重定向到 https。

在 Heroku 中,我删除了 SSL 应用程序以及 PointDNS 中指向 osaka-4635.herokussl.com 的指针。

至于现在我在 PointDNS 中有以下内容:

  • 从 root 到 dnsx.pointhq.com 的 NS 指针
  • 从 root 到 heroku 应用程序的别名
  • 从 www 到 heroku 应用的 CNAME

这里有什么问题还是后端代码中的某些地方需要更改? 问题可能出在我们的 DNS 提供商而不是 Heroku 上吗?

同样,我只想删除 https。

提前致谢!

编辑:

在项目文件夹中搜索“https”并在我们的网址硬编码 (https://www.sitename/..) 的几个文件中找到它,所以我知道所有这些都需要更改为 http。除此之外,我在以下文件中找到了它(后跟代码)。

中间件.py:

class RequestSSLMiddleware(object):
    def process_request(self, request):
        if not any((DEBUG, request.is_secure(), request.META.get('HTTP_X_FORWARDED_PROTO', '') == 'https')):
            url = request.build_absolute_uri(request.get_full_path())
            secure_url = url.replace('http://', 'https://')
            return HttpResponsePermanentRedirect(secure_url)

class ResponseSSLMiddleware(object):
    def process_response(self, request, response):
        if not DEBUG:
            if 'Location' in response:
                if response['Location'][0] == '/':
                    response['Location'] = 'https://' + get_current_site(request).domain + response['Location']
        return response

settings_base.py:

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

gunicorn.conf:

secure_scheme_headers = {
    'X-FORWARDED-PROTO': 'https'
}

settings.py:

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

我想我面前有一些工作要做...但是对于那些了解代码的人来说,在这种情况下从 https 更改为 http 可能需要做很多工作吗?

最佳答案

在 settings.py 或 settings_base.py 中找到 MIDDLEWARE_CLASSES,并注释包含“RequestSSLMiddleware”和“ResponseSSLMiddleware”的行。这些是自定义中间件类,不是 Django 提供的。

在 settings.py 中注释包含 SECURE_PROXY_SSL_HEADER 的行,不再需要,因为您不需要 https。

关于python - Heroku 仍然重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27439879/

相关文章:

python - 通过 Django ManyToMany 高效查询额外字段

django 的 timezone.now 不显示正确的时间

ssl - 在 WorldClient、MDaemon 12 中安装 SSL 证书

python - 有没有办法从 POST/PUT 中与 Tornado 服务器异步检索正文?

python - 可以使用 jira-python 读出搜索过滤器

python - PyQt4 TextEdit.clear 导致崩溃

python - Pandas 保留索引排序

python - django-tables2 将动态列从 hstore 添加到表类

java - 如何在我的 Java Web 服务客户端请求中使用 SSL/TLS 握手

wordpress - 控制台错误 : Mixed content, 但我在代码中找不到链接