400 bad request-The plain http request was sent to https port nginx

+1 vote

I've created an ingress rule for my cluster but when I go to the port and try to open it, I get the following error:

Oct 24, 2018 in Kubernetes by Hannah
• 18,520 points
35,001 views

3 answers to this question.

0 votes

You encounter this error because every time a client tries to access your site via HTTP, the request is redirected to HTTPS. It’s because the nginx expects SSL to be used in the transaction yet the original request was plain HTTP, it complains with the error.

In you nginx config file comment the the following line

#ssl on
answered Oct 24, 2018 by Kalgi
• 52,350 points

I am using openshift 4.3 and I have created route with target port 443. In my nginx I have something like this

server {

   
    listen       8080;
    
    <% if ENV["HTTPS__ENABLED"] == "true" %>
    listen <%= ENV["HTTPS__PORT"] %> ssl;
    # These files are generated by the node app
    ssl_certificate /cert.csr;
    ssl_certificate_key /tls_private_key.csr;
    ssl_protocols TLSv1.2;
    <% end %>
    server_name <%= ENV["DEFAULT_SERVICE_NAME"].sub("https://", "") || localhost %>;

I get this error
 

400 Bad Request

The plain HTTP request was sent to HTTPS port

Did you expose your Pod?
0 votes

You usually get this error when you try to configure you Nginx to handle both HTTP and HTTPS requests. 

To fix this error, comment out the line below in your configuration or set it to off.

#ssl on 
OR
ssl off

Save and close the file. Then restart the nginx service.

# systemctl restart nginx
OR
$ sudo systemctl restart nginx
answered Apr 30, 2019 by Kavya
0 votes

If you check your config file, it says "listen to port 80"(HTTP) and "SSL on". When you point your browser to http://localhost, it tries to connect via HTTP but since you have mentioned SSL it expects to use SSL. 

What you can do is have two separate servers, something like this:

server {
  listen 80;

  // other directives...
}

server {
  listen 443;

  ssl on;
  // SSL directives...

  // other directives...
}
answered Apr 30, 2019 by Vaidya

Related Questions In Kubernetes

0 votes
1 answer

The connection to the server 192.168.99.101:8443 was refused - did you specify the right host or port?

Hi@akhtar, This error may occur because of network ...READ MORE

answered May 21, 2020 in Kubernetes by MD
• 95,460 points
4,287 views
0 votes
1 answer

The connection to the server localhost:8080 was refused - did you specify the right host or port?

Hi@akhtar, You may get this error if Kubectl ...READ MORE

answered Jun 6, 2020 in Kubernetes by MD
• 95,460 points
41,236 views
+2 votes
0 answers

The connection to the server localhost:8080 was refused

$ kubectl get svc The connection to the ...READ MORE

Aug 8, 2019 in Kubernetes by Lakshminarayanan
17,410 views
+1 vote
1 answer
0 votes
1 answer

permissions related to AWS ECR

if you add allowContainerRegistry: true, kops will add those permissions ...READ MORE

answered Oct 9, 2018 in Kubernetes by Kalgi
• 52,350 points
1,401 views
0 votes
3 answers

Nginx reverse proxy URL getting rewritten

Hey @Gopi, try your ingress probably like ...READ MORE

answered Feb 12, 2019 in Kubernetes by Kalgi
• 52,350 points
4,729 views
0 votes
2 answers

Not able to expose port 80 on the host, kubernetes ingress

I was facing the same error. The nginix ...READ MORE

answered Sep 11, 2018 in Kubernetes by Kalgi
• 52,350 points
2,125 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP