【发布时间】:2014-12-12 08:48:43
【问题描述】:
几天前我从我们的网站上删除了 SSL,但遇到了很多问题。但是,大部分都已经解决了,只有一个存在:一个被重定向到 https,即使你输入了 http。
在 Heroku 中,我删除了 SSL 应用程序以及 PointDNS 中指向 osaka-4635.herokussl.com 的指针。
目前我在 PointDNS 中有以下内容:
- 从根到 dns 的 NS 指针x.pointhq.com
- 从根到 heroku 应用的别名
- CNAME 从 www 到 heroku 应用程序
这里有问题还是后端代码中的某些内容需要更改? 问题可能出在我们的 DNS 提供商而不是 Heroku 上吗?
再次,我只想删除 https。
提前致谢!
编辑:
在项目文件夹中搜索“https”并在我们的网址被硬编码的几个文件中找到它 (https://www.sitename/...) 所以我知道所有这些都需要更改为 http。除了我在以下文件中找到它(后面是代码)。
middleware.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 可能需要很多工作吗?
【问题讨论】:
-
检查您的 htaccess。如果里面什么都没有,可能是代码重写了
$_SERVER['HTTPS']。 -
@Deer-Outdoor.nl:谢谢。对于这行代码,我应该查看一个特定的文件吗?
-
在您的 htaccess 中查找带有 https 重写的内容,并在代码中查找检查 $_SERVER['HTTPS'] 是否为 http 并将其重定向到 https 的内容。
-
@Deer-Outdoor.nl:在所有文件中搜索 $_SERVER['HTTPS'] 但不匹配,所以我想我必须检查 htaccess。我在哪里可以找到/访问这个文件(同样,我在 Heroku 上使用 python/django)?
-
在您的代码中搜索类似
server { listen 80; rewrite ^(.*) https://$host$1 permanent; }的内容。 htaccess 主要位于网站的根目录中。
标签: python django ssl heroku https