nginx redirect HTTPS to HTTP

keno picture keno · Aug 12, 2010 · Viewed 60.6k times · Source

How can i redireect from https to http?

i have the code below but it does not seem to work.

server {
        listen 443;
        server_name example.com;
        rewrite ^(.*) http://example.com$1 permanent;
 }

Answer

brupm picture brupm · Apr 21, 2011

The answer above will work, you need to generate a self signed cert (or have a real one) and configure nginx as such:

server {
  listen *:443;
  ssl on;
  server_name domain.com;
  rewrite ^(.*) http://domain.com$1 permanent;

  ssl_certificate      /data/certs/domain.crt;
  ssl_certificate_key  /data/certs/domain.key; 
 }

Keep in mind, if it is a self signed cert the browser will give you an ugly warning.