Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect HTTPS to HTTP on NGINX?

Is there a way to redirect HTTPS requests to HTTP by adding a rule in the domain's vhost file?

like image 583
deb Avatar asked Oct 08 '10 19:10

deb


People also ask

How do you configure HTTP to HTTPS redirect in nginx?

Redirect HTTP to HTTPS version for Specified domain in NginxServer_name domain-name.com www.domain-name.com – it specifies the domain names. So, replace it with your website domain name that you want to redirect. Return 301 https://domain-name.com$request_uri – it moves the traffic to the HTTPS version of the site.

Can we redirect HTTPS to HTTP?

When you add an SSL certificate to a domain on your hosting account, the domain will default to being served over HTTPS. If you do not want your site to use HTTPS to serve your site securely, you can change the default from HTTPS to HTTP.


1 Answers

Why is something like that useful? At first look I wasn't sure if it could be done. But it presented an interesting question.

You might try putting a redirect statement in your config file and restarting your server. Two possibilities might happen:

  1. The server will issue the redirect - what you seem to want.
  2. The server will first do the https exchange, and THEN issue the redirect, in which case, what's the point?

Will add more if I come up with something more concrete.

UPDATE: (couple of hours later) You could try this. You need to put this in your nginx.conf file -

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

Sends a permanent redirect to the client. I am assuming you are using port 443 (default) for https.

server {     listen      80;     server_name _ *;     ... } 

Add this so that your normal http requests on port 80 are undisturbed.

UPDATE: 18th Dec 2016 - server_name _ should be used instead of server_name _ * in nginx versions > 0.6.25 (thanks to @Luca Steeb)

like image 178
Srikar Appalaraju Avatar answered Sep 29 '22 15:09

Srikar Appalaraju