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

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;
            }
    }
...
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.