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

I have a series of command that are common, and would like to apply these as defaults for every site.

For example, the two or three lines that tell Nginx how to handle PHP, where to listen for SSL, to cache img's and to deny hidden files.

To include these as the default for every site, it needs the equivalent of adding them to the http{} directive.
This cannot be easily done, as the location must be put into the server block.

The standard solution - which seems to me pretty messy and inept - is to save these as a file such as common.conf, and to include them in each server. This breaks up the logic in a silly way. It also looks messy when multiplied over several dozen sites. But it works.

Except that occasionally I need to overwrite the the defaults. Perhaps I need to view my hidden files or treat htm special.

Nginx doesn't allow for me to redeclare a location. So once it is in common, I cannot give it different directions for this one site.

The only solution I found is to break up the common into the individual parts. So I have 12 includes for every single one of several dozen sites, before writing my first custom per-site line.

Terribly error prone and messy.

Is there a better way?

share|improve this question
    
I'm not exactly sure why you have so much copy-pasting going on, or why you define some locations in common, which then have to be redefined. –  cnst Jan 21 at 22:18

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.