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

Problem

When viewing any of my sites using port 80, the following error appeared on non-SSL websites:

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

Original server block:

server {
    listen 80;
    listen 443;

    ssl on;
    ssl_certificate         /path/to/cert/example.pem;
    ssl_certificate_key     /path/to/cert/example.private.key;

    root /path/to/wordpress;
    index index.php;

    # Website URL
    server_name blog.duaneleem.com;

    # etc...
}

 

Solution

After reading NGINX documentation, the solution to this was to place the SSL directive on “listen.” Here’s a sample server block that demonstrates this:

server {
    listen 80;
    listen 443 ssl;

    ssl_certificate         /path/to/cert/example.pem;
    ssl_certificate_key     /path/to/cert/example.private.key;

    root /path/to/wordpress;
    index index.php;

    # Website URL
    server_name blog.duaneleem.com;

    # etc...
}

By adding “ssl” to the listen directive to all my server blocks, everything started working again.

Source: nginx.org

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: