Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx error location for all servers

Is it possible to define a common location for all servers? From nginx location documentation I've seen that location depends on server. I would like to do something like this:

...
http {
    error_page  404                    /error/404.html;
    error_page  500 501 502 503 504    /error/50x.html;

    location ^~ /error/ {
        internal;
        root /var/www/nginx/errors;
    }

    server {
        ...
    }

    server {
        ...
    }
    ...
}

I've tried setting:

http {
    ...
    root /var/www/nginx/errors; # also with root /var/www/nginx
    ...
}

with no success: always showing nginx default error page.

like image 892
Miquel Avatar asked Jul 04 '14 10:07

Miquel


1 Answers

Is it possible to define a common location for all servers?

No.

You could make separate file and include it into all your servers.

/etc/nginx/error-location.inc:

location ^~ /error/ {
    internal;
    root /var/www/nginx/errors;
}

And then:

server {
    ...
    include error-location.inc;
}

server {
    ...
    include error-location.inc;
}
like image 56
Alexey Ten Avatar answered Nov 18 '22 09:11

Alexey Ten