2

I have a private HTTPS server using nginx. Therefore, I don't care about browser compatibility nor HTTP to HTTPS redirection; I just want it to work in my environment and nowhere else. I have already configured it with "listen 17648 ssl;". Whenever I try to connect to it using plain HTTP, I get the infamous "The plain HTTP request was sent to HTTPS port" response.

Is there any way to prevent nginx from sending any response at all when a HTTP request is sent to a HTTPS port? I would like nginx to simply close the connection if the request is not SSL, or maybe return some SSL-level error but no plain HTTP response at all, not even an error response.

4

From Nginx documentation about the return clause:

The non-standard code 444 closes a connection without sending a response header.

So I've tried to catch the error 497 "HTTP to HTTPS" and tried to return the 444 this way:

error_page 497 =444 @close;

location @close {
   return 444;
}

Unfortunately this leads to a "pending" state due to this bug

Using the workaround proposed by the developer it seems to work:

error_page 497 =444 @close;

location @close {
   return 0;
}

Try if this fits your needs!

1
  • Thanks. Unfortunately, it doesn't seem to work in my case (nginx 1.6.2). curl -v shows that the server is still sending a reply with status code 444 and there are several headers, including the Server header. – user427569 Dec 15 '15 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.