Redirect invalid url in default Error Page

Posted By : Himanshu Goyal | 07-Jan-2017

Intro :When you use nginx as a proxy server in your web application ,then any person hit on invalid url then you can show the default error page by default .It is easy to set the default 404 url in nginx. During hit on invalid url nginx gave 404 error code and error_page 404 /404 this property will rediect /404 url on nginx when 404 occur.


After redirect to this url  you just send the static html page and these step make to look better to you website .Things to remember :

A)You must define the root path of project in root property in Nginx server .

B)After root path make the 404 name folder and place the 404 html in it .This html will be show during invalid url access.

C)Define the error page  property in nginx default file .this property will be redirect 404 url when 404 error occur .

D)You must define the path of html in locaton property for display during 404.

Below is sample code help :

 

server {

listen       5001;
        server_name  localhost;

        root   /home/himanshu/Documents/tihm/TIHM-FE;

        location / {
                index index.html;
                #try_files $uri $uri/ /index.html;
        }

          error_page 404 /404;

	 location /404 {
        index 404.html;  //404.html page must be in the after root path 404 folder
    }
 

About Author

Author Image
Himanshu Goyal

Himanshu is a bright Java ,Mean stack developer and have good knowledge of Hibernate, Spring,FFmepg,Neo4j JSON, Jquery, NODE.JS .His hobbies are learning new things, fitness .

Request for Proposal

Name is required

Comment is required

Sending message..