Skip to content

How to fix “the plain http request was sent to https port”?

Setting up a server on any OS can be a bit of a challenge, especially when dealing with security protocols like SSL. If you incorrectly set up a server configuration to handle HTTP and HTTPS requests, you can run into quite a few errors.

One such error with Nginx is the “paint HTTP request was sent to HTTPS port”. The error arises when you haven’t enabled SSL on your Nginx configuration. Meaning when a client tries to open http://site.com (or HTTP port 80), the server will try to use HTTPS by default resulting in this error.

On the other hand, if a client tries to connect to https://site.com, the site will work just fine as the URL securely connects to the server. 

Also read: How to check Nginx_status?


How to fix this error?

Fixing this issue is relatively simple. Nginx expects SSL to be used when an original request connects via plain HTTP to port 80, enabling SSL to eliminate the error.  All you have to do is modify your Nginx configuration to enable (or disable) SSH access.

For reference, this is how the default configuration file in Nginx looks like. If you don’t want to change your existing configuration file, you can use this configuration to resolve the issue.

server{
        listen 80;
        server_name example.com www.example.com;
        return 301 https://www.example.com$request_uri;
}
server {
        listen 443 ssl http2;
        server_name example.com www.example.com;

        root   /var/www/html/example.com/;
        index index.php index.html index.htm;

        #charset koi8-r;
        access_log /var/log/nginx/example.com/example.com_access_log;
        error_log   /var/log/nginx/example.com/example.com_error_log   error;

        # SSL/TLS configs
        ssl on;
        ssl_certificate /etc/ssl/certs/example_com_cert_chain.crt;
        ssl_certificate_key /etc/ssl/private/example_com.key;

        include /etc/nginx/ssl.d/ssl.conf;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /var/www/html/example.com/;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {

                root   /var/www/html/example.com/;
                fastcgi_pass   127.0.0.1:9001;
                #fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include         fastcgi_params;
                include /etc/nginx/fastcgi_params;

        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
}

Just open your configuration file and find the SSL toggle, which looks like ‘ssl on;’. Just uncomment the line containing the SSH instruction you want to implement (enabling or disabling) and save the file.

After that, you need to restart the Nginx server using the command below, and you’re good to go. 

sudo systemctl restart nginx

If you’re facing this error while using the Apigee API, you can check out this guide for possible causes and solutions.

Also read: Linux no space left on device: 3 Fixes

Hello There!

If you like what you read, please support our publication by sharing it with your friends, family and colleagues. If you're running an Adblocker, we humbly request you to whitelist us.

Share on facebook
Share on whatsapp
Share on twitter
Share on reddit
Share on linkedin
Share on pocket
Share on pinterest
Share on telegram
Share on stumbleupon
Share on digg
Share on tumblr
Share on email
Share on skype
Share on xing
Share on vk
Share on odnoklassniki
Share on mix








>