Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have an nginx configuration with a whole bunch of server {} blocks. I want to share error pages between them all, but many of them have different document roots. I can use a configuration like

error_page   404              /404.html;
error_page   500 502 503 504  /50x.html;

outside of the server blocks and it gets shared, but then I have to put those same documents in all the roots, or have rules like

location = /404.html {
    root /srv/http/errors;
}
location = /50x.html {
    root /srv/http/errors;
}

in all my server blocks.

Is there a way to share these documents without repeating myself over and over or having many copies in the filesystem?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Use the magic of an include directive to specify all the necessary boilerplate, then just include /etc/nginx/standard-error-pages.conf in each vhost (make it part of the standard vhost template in your config management system). This also makes it real easy to override the error pages for a specific vhost (by not putting the include into that vhost config).

share|improve this answer

Your Answer

 
discard

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.