How to redirect every https request to http in Nginx?

This questions has been asked many times on StackOverflow but my question differs a bit :

I have multiple sub domain websites :

  • http://www.example.com
  • http://my.example.com
  • https://admin.example.com
  • http://client.example.com

As you can see, only admin is served through https.

I successfully created all my virtual hosts in Nginx and this works well.

But now, I would like to redirect all the clients that tries to access to other sub websites via https to http :

  • https://www.example.com => redirect to http://www.example.com
  • https://my.example.com => redirect to http://my.example.com
  • https://client.example.com => redirect to http://client.example.com

=> only admin does the opposite.

My first thought was to set each https domain with a redirect :

server {
    listen 443;
    server_name www.example.com;

    rewrite         ^(.*)    http://www.example.com$1;
}

And did this for each subdomains (www, my and client).

But this don't work, I have an SSL error on my browser (SSL record too long).

How can I do that?

Thanks for your help!


You need to include all the ssl stuff for nginx in the server {}

You need at least

            ssl                  on;
            ssl_certificate      /etc/ssl/domain.com.crt;
            ssl_certificate_key  /etc/ssl/domain.com.key;