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

use*_*236 5 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**
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题呢?拜托我需要你的帮忙。这个问题以前不存在。到目前为止我还找不到解决方案。

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;


}
}
Run Code Online (Sandbox Code Playgroud)

Oli*_*ver 3

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

SECURE_SSL_REDIRECT = False
Run Code Online (Sandbox Code Playgroud)