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?
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.