Multiple 404 error pages in nginx

I am starting the nginx server. I want to serve a custom error page only for a specific request. Request example

http://localhost/abc1 & http://localhost/abc2

If these pages do not exist, I want to serve the user error page. This user error page should only be displayed for the above links, other page errors may display the default error page. I tried a different configuration but nothing works. Thoughts

Regards, Farrukh Arshad

+4
source share
2 answers

Ok, I found the answer. The trick is that you must explicitly define error_page for all of these special locations. Here is the configuration that worked for me.

location / {
    root   /var/www/nginx-default;
    index  index.html index.htm;
    error_page 404 /404.html;
}

location /abc1.html {
    root   /var/www/nginx-default;
    error_page 404 /special_error.html;
}
location /abc2.html {
    root   /var/www/nginx-default;
    error_page 404 /special_error2.html;
}

nginx, , , "location". , . ,

http://localhost/abc1.html 

http://localhost/abc1 

"" , . , - nginx . .

+1

, , , html, , ,

server {
    listen 80;
    root   /var/www/nginx-default;

    location /abc1 {        
        error_page 404 /special_error.html;
    }

    location /abc2 {
        error_page 404 /special_error2.html;
    }
}
+2

All Articles