How to redirect a URL in NGINX

How to redirect a http://test.com to http://www.com

Your main server block will be like

server {
            listen       80;
            server_name  www.test.com;
            client_max_body_size   10M;
            client_body_buffer_size   128k;

            root       /home/test/test/public;
            passenger_enabled on;
            rails_env production;

            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                    root   html;
            }
    }



Then add a new server block with the below code.

server {
        server_name test.com;
        return 301 $scheme://www.test.com$request_uri;
}



You are done!

Comments

Popular posts from this blog

How to SSH to remote server without entering password each time.

Ruby on Rails Installation on Windows 7