Https to Http Redirection In Nginx

0 Flares 0 Flares ×

So how do you redirect https to http in Nginx? This is generally the opposite of what everybody does http to https redirection. Sometimes it is required to run all your service under http only so in that case you need to do a redirection. This procedure explains the method to achieve the redirection.

 

Process to Redirect Https to Http in Nginx

 

I am assuming that you are already familiar with the configuration of Nginx server. So here we are going to modify the nginx.conf file which is the main configuration file for Nginx. Open this configuration file and follow the instruction below.

In the https server module of your configuration file you need to add a redirection rule which would permanently rewrite the URL to http. So find the example configuration below:

server {

                 listen 80;

                 server_name example.com;

                 […..]

}

server {

                 listen 443;

                 server_name example.com;

                 ssl on;

                 rewrite ^ http://$server_name$request_uri? permanent;  //Magic line

                 […..]

}

This is a permanent redirection from https to http so whatever request goes to https URL, those requests will be redirected to http permanently.

Did you see how simple was that, sometimes a simple trick could do a big job for you. This configuration is mostly useful for those bloggers and webmasters who run their blog on VPS server and use Nginx as a load balancer.

Guru

+Ayodhyanath Guru holds a B.Tech degree in Electrical Engineering and has worked with various prestigious clients in the IT industry and presently working as a Software Engineer. He is a part time blogger and presently authors the Jafaloo.Com blog. Being a tech enthusiast Guru likes to surf the web and blogs about interesting technical topics like How-To guides, freewares, Tutorials, Software, Gadgets, web applications etc. Apart from blogging he likes coding in Java/J2EE and PHP.

You may also like...

1 Response

  1. Suraj Sharma says:

    Dear Friend,
    Don’t you think with the approach you have given we NEED to have ssl certificates for the server, otherwise people coming from 443 will see that Ugly browser certification exception.
    The reason is that any ssl/443 connection requires the certificates at the handshake only and later comes the role for any rewrite/returns.
    So the handshake will only show us that ugly message.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 0 Flares ×