Nginx出现The plain HTTP request was sent to HTTPS port

Nginx突然出现了下面的问题:

The plain HTTP request was sent to HTTPS port

在博客配置ssl证书的时候,博客的https地址和http地址是都能访问,不过,今天突然发现博客访问出现上面的问题,经过百度找到了问题的解决办法,在此记录一下。

解决办法:

删掉ssl on; 并在 listen 443; 443后加上ssl即可。
Nginx最新配置文件内容如下:

server {
    listen     80;
    listen     443 ssl; 
    
    server_name  www.ydstudio.net  ydstudio.net;
    set $my_server_name $scheme://$server_name;
    root  html;
    
    if ($host = 'ydstudio.net') {
      rewrite ^ https://www.ydstudio.net$request_uri? permanent;
    }
    #防止ip访问,如http://xxx.xxx.xxx.xxx或者https://xxx.xxx.xxx.xxx
    if ( $host ~* "\d+\.\d+\.\d+\.\d+" ) {
        rewrite ^ https://$server_name;
    }
    
    if ( $my_server_name != https://$server_name ) {
       return      301 https://$server_name$request_uri;
       #rewrite ^ https://$server_name$request_uri? permanent;
    }
    
    location / {
       try_files $uri $uri/ /index.php$is_args$args;
       index index.php  index.html index.htm;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    } 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
       #root           html;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  html/typecho/$fastcgi_script_name;
       include        fastcgi_params;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
        #expires指令设置浏览器缓存过期时间
        #可以在http、server、location三个作用域中设置
        #缓存图片或视频30天
        expires 30d;
    }

    location ~ .*\.(js|css)?$ {
        #缓存js/css 1小时
        expires 1h;
    }
 
    #ssl on;
    ssl_certificate   cert/214353452860792.pem;
    ssl_certificate_key  cert/214353452860792.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
}

相关文章

此处评论已关闭