4

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?

3
  • 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, 2013 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, 2013 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, 2013 at 8:32

1 Answer 1

3

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.