一个微调解决“nginx: 400 Bad Request | The plain HTTP request was sent to HTTPS port”

服务器配置了HTTP和HTTPS同时兼容,某天使用HTTP访问时,出现nginx: 400 Bad Request | The plain HTTP request was sent to HTTPS port,这个,认真仔细查看配置文件一遍又一遍,没发现问题,原配置文件如下:

server
    {
        listen 80;
        server_name xxxxxxxxxx;
        index index.html index.htm;
        root    /www/mini/;
        listen 443;
        ssl on;
        ssl_certificate /usr/local/nginx/conf/ssssssssssssssss;
        ssl_certificate_key /usr/local/nginx/conf/sssssssssssssss;
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:50m;
        ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

    location / {
#        client_max_body_size    100m;
        proxy_pass http://127.0.0.1:8080;   #来自jsp请求交给tomcat处理
        proxy_redirect off;
        proxy_set_header Host $host;    #后端的Web服务器可以通过X-Forwarded-For>获取用户真实IP
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade; #wss协议相关配置
        proxy_set_header Connection "Upgrade"; #wss协议相关配置
        proxy_http_version 1.1;
        client_max_body_size 100m;  

一个微调解决“nginx: 400 Bad Request | The plain HTTP request was sent to HTTPS port”_第1张图片
上图是访问结果;
参考官方文档解决方案如下:

server
    {
        listen 80;
        server_name xxxxxxxxx;
        index index.html index.htm;
        root    /www/mini/;
        listen 443 ssl;  #注意这里 
#       ssl on;          #注意这里
        ssl_certificate /usr/local/nginx/conf/sssssssssssssss;
        ssl_certificate_key /usr/local/nginx/conf/sssssssssssssss;
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:50m;
        ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

    location / {
#        client_max_body_size    100m;
        proxy_pass http://127.0.0.1:8080;   #来自jsp请求交给tomcat处理
        proxy_redirect off;
        proxy_set_header Host $host;    #后端的Web服务器可以通过X-Forwarded-For>获取用户真实IP
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $pro
        xy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade; #wss协议相关配置
        proxy_set_header Connection "Upgrade"; #wss协议相关配置
        proxy_http_version 1.1;
        client_max_body_size 100m; 
        ...
        ...

修改完以后重启,很自然的就好了;

你可能感兴趣的:(一个微调解决“nginx: 400 Bad Request | The plain HTTP request was sent to HTTPS port”)