nginx: 400 Bad Request | The plain HTTP request was sent to HTTPS port

大飛_dafei發表於2018-03-01

nginx版本1.0.4 


nginx一般情況下配置;

server {
    listen 443;
    server_name localhost;
    ssl on;
    root html;
    index index.html index.htm;
    ssl_certificate   cert/214525134250577.pem;
    ssl_certificate_key  cert/214525134250577.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;
    location / {
        root html;
        index index.html index.htm;
    }
}

然後神器的一幕發生了,首先是: nginx: [warn] invalid value "TLSv1.1"  nginx: [warn] invalid value "TLSv1.2"

把 TLSv1.1 TLSv1.2 刪掉;報錯  nginx: 400 Bad Request | The plain HTTP request was sent to HTTPS port


參考官方文件解決如下:

server {
    listen 80;
    server_name localhost;
    root html;
    index index.html index.htm;
   
    
    listen 443 ssl;  #注意這裡
    #ssl on;
    ssl_certificate      cert/214525134250577.pem;
    ssl_certificate_key  cert/214525134250577.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1;
    ssl_prefer_server_ciphers on;

    location / {
        root html;
        index index.html index.htm;
    }
}

刪掉 ssl on; 並在 listen 443; 後面加上ssl即可 

nginx官方文件

相關文章