django - 如何停止从本地主机重定向到 https

标签 django http nginx digital-ocean

我有一个使用 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;


}
}

最佳答案

在本地运行网站时,您需要禁用重定向到 HTTPS
为此,请在您的设置中将 SECURE_SSL_REDIRECT 设置为 False:

SECURE_SSL_REDIRECT = False

关于django - 如何停止从本地主机重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48908543/

相关文章:

node.js - 为什么对 Ingress (GKE) 的此 HTTP GET 请求始终返回 400(错误请求)错误?

javascript - 将 session cookie传递给另一个ip?

mysql - sudo systemctl start 返回 "Failed to wait for response: Success"

mysql - 如何在django中按列分配查询结果值

python - 在 django 中重置密码?

ruby - 使用 TCPServer 的 Ruby 中的简单 HTTP 服务器

Docker Compose 与 NGINX 代理传递不起作用

python - 在 Django 中提交表单时找不到页面(404)

python - save() 收到意外的关键字参数

Nginx:获取proxy_pass使用的上游URI