如何停止从 localhost 重定向到 https
Posted
技术标签:
【中文标题】如何停止从 localhost 重定向到 https【英文标题】:How to stop redirection from local host to https 【发布时间】:2018-08-01 04:32:57 【问题描述】:我有一个使用 Django 的网站。我们的网站总是有一个重定向为 https。在本地主机上引起问题的问题。错误是:
**An error occurred during a connection to 127.0.0.1:8000. SSL received a record that exceeded the maximum permissible length. Error code: SSL_ERROR_RX_RECORD_TOO_LONG**
如何解决这个问题?拜托我需要你的帮忙。这个问题以前不存在。直到现在我都找不到解决方案。
nginx配置为:
server
listen 80;
listen [::]:80;
server_name www.website.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
client_max_body_size 6m;
if ($scheme = http)
return 301 https://website.com$request_uri;
location /static
alias /home/website/staticfiles;
autoindex on;
expires max;
gzip on;
gzip_types text/plain text/css application/json application/x-javascript text/xml
application/xml application/xml+rss text/javascript;
location /media
alias /home/website/media;
autoindex on;
expires max;
location /
proxy_pass http://127.0.0.1:8000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server
listen 443 ssl;
listen [::]:443 ssl;
server_name IP website.com;
ssl_certificate /home/website/website.com.crt;
ssl_certificate_key /home/website/website.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers '';
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
client_max_body_size 6m;
location /static
alias /home/website/staticfiles;
autoindex on;
expires max;
gzip on;
gzip_types text/plain text/css application/json application/x-javascript text/xml
application/xml application/xml+rss text/javascript;
location /media
alias /home/website/media;
autoindex on;
expires max;
location /
proxy_pass http://127.0.0.1:8000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
【问题讨论】:
你能澄清你想要重定向的内容吗?当您通过 localhost 运行站点时,您是否尝试在本地设置 SSL? 我在我的计算机上使用 python manage.py runserver localy ...但是127.0.0.8000 被重定向为 https 并出现此错误 看我的回答,希望对你有帮助。 【参考方案1】:在本地运行网站时,您需要禁用重定向到 HTTPS
为此,请在您的设置中将 SECURE_SSL_REDIRECT
设置为 False:
SECURE_SSL_REDIRECT = False
【讨论】:
以上是关于如何停止从 localhost 重定向到 https的主要内容,如果未能解决你的问题,请参考以下文章