Skip to content

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

  • by
  • 3 min read

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 (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, 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.

        listen 80;
        return 301$request_uri;
server {
        listen 443 ssl http2;

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

        #charset koi8-r;
        access_log /var/log/nginx/;
        error_log   /var/log/nginx/   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/;

        # proxy the PHP scripts to Apache listening on
        #location ~ \.php$ {
        #    proxy_pass;

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

                root   /var/www/html/;
                #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


Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: [email protected].