Tag Archives: Nginx 400 Bad Request

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

Nginx configuration file:

server {    
    listen       80;
    listen       443;
    server_name www.xxx.com;


    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    
    ssl on;
    root html;
    index index.html index.htm;
    ssl_certificate   /etc/nginx/conf.d/cert/214567143360012.pem;
    ssl_certificate_key  /etc/nginx/conf.d/cert/214567143360012.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;
}

It is normal to access HTTPS, but when accessing HTTP, there will be
400 bad requestthe plain HTTP request was sent to HTTPS port error

A normal HTTP request is sent to the HTTPS port

Referring to the official documents, the solution is as follows:

server {
    listen       80;
    listen       443  ssl;
    server_name www.xxx.com;


    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    root html;
    index index.html index.htm;
    ssl_certificate   /etc/nginx/conf.d/cert/214567143360012.pem;
    ssl_certificate_key  /etc/nginx/conf.d/cert/214567143360012.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;
}

Delete SSL on; And in listen 443; 443 and then add SSL