I've this really weird behaviour with my ubuntu 10.04 / nginx 1.2.3 server. Basically I changed the SSL certificates this morning. And ever since it has been behaving weirdly on all apps. Godaddy is reporting that HTTPS/SSL setup is correct.

When I try a page it still works correctly when I'm using HTTPS. But when I try using HTTP nginx reports error :

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

After looking around on google for hours, I've tried different setup (while originaly my setup was working correctly for longtime, I just renewed certificates)

I kindof found a half solution by adding this to my config :

error_page 497 $request_uri;

The realllly weird thing is that when I use this setup :

server {
    listen 80;
    server_name john.johnrocks.eu;

    access_log /home/john/envs/john_prod/nginx_access.log;
    error_log /home/john/envs/john_prod/nginx_error.log;

    location / {
        uwsgi_pass unix:///home/john/envs/john_prod/john.sock;
        include uwsgi_params;

    location  /media  {
        alias   /home/john/envs/john_prod/johntab/www;

    location  /adminmedia  {
        alias   /home/john/envs/john_prod/johntab/www/adminmedia;

I still have the same error when using HTTP (while nothing is setup for HTTPS here)??

I'm getting crazy on this !


Even with this config :

server {
    listen       80;
    server_name  john.johnrocks.eu;

    access_log  /home/john/envs/john_prod/nginx.access.log;

    location / {
        root   /home/john/envs/john_prod/johntab/www;
        index  index.html index.htm;

I get error 400 (The plain HTTP request was sent to HTTPS port) on everything I try to load ..

  • Basically it seems that all traffic is redirect to the 443 port whether I try seeing a page with http or https So all my apps are working correctly in https but when I try http I get error 400 "the plain http request was sent to https port" The weird thing is that I didn't change my setup All was working fine before I just renewed the ssl certificates from godaddy Any idea ?????? – dwarfy Sep 20 '12 at 8:25
  • Now I have change my vhost file many times with suggestions from internet doesn't change a thing I halve fixed it with error_page 497 $request_uri; so it's a trick that catch the error and return what's requested instead now my webpage is completely weird it loads, but all the additional resources are loaded, but with error 400 – dwarfy Sep 20 '12 at 8:26

I don't know about the 400 error, but if you had an 301 (permanent) redirect in your previous config, the browser might still have stored this redirect in the cache and doesn't check the original. Maybe purging your caches might help.


So I found out what the problem was. The problem comes from how nginx loads the vhosts configurations. If you look at nginx.conf, you will find this line

include /etc/nginx/sites-enabled/*;

So this loads all the "vhosts" into the main nginx.conf in a random order. So what happend is that the error was somewhere else, in another vhost .. and it was making all the vhosts fail basically (no error was detected by nginx, it was not an error per se but a bad configuration).

So I removed all the sites-enabled vhosts, and put them back one by one, reloading nginx and testing the site each time until I got them all right and then voilà

  • Thanks for sharing how you fixed it. Why don't you select your answer as the right answer? – Pothi Kalimuthu Sep 21 '12 at 10:55

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.