nginx error location for all servers
Asked Answered
L

1

10

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.

Limen answered 4/7, 2014 at 10:17 Comment(0)
Z
20

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;
}
Zenithal answered 4/7, 2014 at 10:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.