404 (NOT FOUND) error redirection to your custom page in nginx.
Hi Friends,
As per my company requirement I had to configure redirection for 404 error to our custom page "404.html" in nginx.
Follow below steps :-
Step #1. Make your custom page 404.html which you want to display.
Step #2. Keep 404.html at any location my location is
"/var/www/web1/domains/www.example.com/web/error/".
Step #3. Edit your nginx config file.
[root@ip ~]# vim /etc/nginx/conf.d/example.com.conf
server {
server_name marriage.com;
rewrite ^ $scheme://www.example$request_uri redirect;
}
server {
server_name www.example.com;
root /var/www/web1/domains/www.example.com/web;
index index.php index.html index.htm;
access_log /var/log/nginx/example.com_access.log upstream;
error_log /var/log/nginx/example.com_error.log;
## Below code redirect all page not found error to 404.thml page
error_page 404 /404.html;
location = /404.html {
root /var/www/web1/domains/www.example.com/web/error/;
}
Save and Exit.
Step #4 Reload nginx
#service nginx reload
No comments:
Post a Comment