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'm trying to organize my vhost configs in several files, so that there is a view basic files / "templates" and the rest just include them and overwite settings as needed. Here is described, how the inheritance in nginx works. What I'd like to know, is: (how) is it possible to overwtire not the whole setting block / context (e.g. server), but just an option (e.g. server_name).

Example:

I've defined a server block

server {
    listen   80;
    # server_name is not defined

    if ($host ~ ^(?<project>.+)\.(?<area>.+)\.loc$) {
        set $folder "$area/$project";
    }
    ...
}

and want to set/rewrite set the setting server_name in another place. It should be look like

server.server_name foo.bar.loc;

Dotted syntax is not allowed. But maybe there is something like this?

share|improve this question

migrated from stackoverflow.com Feb 9 '13 at 3:11

This question came from our site for professional and enthusiast programmers.

    
For my own curiosity, why would you want to do this? This seems scary, especially with respect to updating this at a later date for one site and killing the rest of them with a bad update. –  CDub Feb 7 '13 at 19:11
    
If it is possible, I could create a very flexible and easy to maintain structure of vhosts on my server, because the code of settings files could be shared by other files. And these "other files" would just include the "main config files/templates" and redefine only a view parameters they need. –  automatix Feb 7 '13 at 21:12
    
To make this possible nginx should have strict execution order for it's config, and then it wouldn't be that fast and efficient –  DukeLion Feb 9 '13 at 8:32
add comment

1 Answer

up vote 0 down vote accepted

Its not supposed to work like that. You cannot override, since nginx config is declarative. I'd advise you to put common configuration into some file, create several server blocks with different parameters and use include directive for that file.

share|improve this answer
    
Yes, that should work. Thank you for the advice! –  automatix Feb 9 '13 at 10:07
add comment

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.