Nginx Ssl On 報錯 400 Bad Request


線上調整了下nginx配置后,出現 

 

400 Bad Request

The plain HTTP request was sent to HTTPS port

 

參考鏈接

https://github.com/alibaba/tengine/issues/854

 

注意ssl on會將整個virtual server都開啟成ssl,比如如下配置,即使listen 80沒有配置ssl,80端口也是使用https協議,如果使用http協議訪問80端口就會返回報錯(400)。
建議開啟ssl使用listen指令,配置中ssl on可以去掉。

server {
   listen 80;
   listen 443 ssl;

   ssl on;    # 將整個server{}開啟成https協議(包括server{}內的80端口)
   ...
}

  

 

開發環境 nginx/1.19.0

存在 ssl on 時, 警告

nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /usr/local/nginx/conf/nginx.conf:39

 

線上環境 nginx/1.13.4

server
{
        listen       80;
        listen       443;
        server_name  example.com;

        ssl on;
        ssl_certificate /usr/local/nginx/conf/ssl/ssl.crt;
        ssl_certificate_key /usr/local/nginx/conf/ssl/ssl.key;
}

存在 ssl on 時, nginx -t 無任何警告提示


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM