1

Wondering if I could get some help. I am unable to serve a custom 403 page. I am using the geoip module to block a few ip addresses. I need to serve a custom xml file as the 403. My problem is that even tho I have set everything up according to the directions (i think) I still get the default nginx 403 page. Please take a look at my /etc/nginx/sites-enabled/default and let me know what is out of place.

.....
###redirect IP_1
geo $bad_user {
default 0;
bad.ip.1/32 1;
bad.ip.2/32 1;
}

server {

....

####custom 403 error page for ip block
error_page 403 /error.xml;
location = /error.xml {
root /var/www/static;
allow all;
}

####redirect IP_2
if ($bad_user) {
return 403;
}

I have verified that directories and xml file have the correct permission. I am able to access the error.xml file if I disable the geoip block. Please let me know if you have any thoughts, ideas or what other info I can provide.

Thanks for your help

user3145049
  • 31
  • 1
  • 4

1 Answers1

2

We were able to solve the issue. The error page and "if bad user" needed to be in the server block. Hope this may help someone else out. Thanks for the assist.

server {

    listen   80; ## listen for ipv4
    listen   [::]:80 default ipv6only=on; ## listen for ipv6

    server_name  localhost;

    access_log  /var/log/nginx/localhost.access.log;

    location / {
        root   /var/www;
        index  index.html index.htm;
        allow all;
        error_page  403  /error.xml;
            if ($bad_user) {
                return 403;
            }
    }
...
}
Jordan Reiter
  • 1,290
  • 4
  • 20
  • 40
user3145049
  • 31
  • 1
  • 4