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
🐧 1 comment so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Can you provide more details regarding where on my computer I enter the script to fix the nginx 403 error?