Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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