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?

automatix
  • 702
  • 3
  • 7
  • 20
  • 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. –  Feb 07 '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 07 '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 09 '13 at 08:32

1 Answers1

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.

DukeLion
  • 3,259
  • 1
  • 18
  • 19