Nginx: Custom Error 403 Page Not Working with IP Deny Configuration

I block or deny access based on the host name or IP address of the client visiting website under nginx web server. I want to display customized e403.html error page, but it doesn't appear to be working. Nginx always displays the built-in, hardcoded "403 Forbidden" error message. Here is my configuration:

.....
...
deny 1.2.3.4;
deny 91.212.45.0/24;
deny 91.212.65.0/24;
.....
...
error_page 403 /e403.html;
location = /e403.html {
root html;
}

How do I fix this problem and display custom error 403 page under nginx server?

The deny parameter will block all access including access to /e403.html file. All you need to add is allow all; inside location directive as follows. Edit /usr/local/etc/nginx/nginx.conf or /etc/nginx/nginx.conf, enter:
# vi /usr/local/etc/nginx/nginx.conf
Update it as follows:

 error_page 403 /e403.html;
location = /e403.html {
root html;
allow all;
}

The above should fix the problem. Once done, reload the nginx web server:
# /usr/local/nginx/sbin/nginx -t && # /usr/local/nginx/sbin/nginx -s reload

Was this answer helpful?

 Print this Article

Also Read

Changing Default SSH port From 22

nano /etc/ssh/sshd_configLook for#Port 22Change "22" to the port you wish to use.CTRL + X, Save...

nginx: Send Custom HTTP Headers

How do I send or set arbitrary HTTP headers using nginx web server? You need to use add_header...

PHP Security: Limit Resources Used By Script

How do I control and put limits on php scripts such as maximum execution time of each script and...

Yum issues with low memory plans (Resolution)

If you are getting yum errors on our 128 or 192 yearly plans with the CentOS/Fedora distro then...

PHP Increase Upload File Size Limit

Your php installation putting limits on upload file size. The default will restrict you to a max...