server_group { } directive?

Jaap Taal jaap at q42.nl
Wed Jan 16 10:59:06 UTC 2013


Hey there,

I was reading about global if's / locations and why it isn't possible.

I would like to suggest the following, maybe it's been suggested
before, who knows:


server_group {
  # this if will be duplicated to each of the server { } configs in
this server_group
  if ( $http_user_agent ~* Googlebot ) {
    return 403;
  }

  server {
    server_name srv1.example.com;
  }

  server {
    server_name srv2.example.com;
  }

}

It's just a way for me to keep the server { } configs very simple,
runtime it should be just like the if would appear twice. With
includes this makes more sense:

nginx.conf:
server_group {
  # this if will be duplicated to each of the server { } configs in
this server_group
  if ( $http_user_agent ~* Googlebot ) {
    return 403;
  }

  include protected-servers/*.conf;
}

protected-servers/srv1.conf:
server {
  server_name srv1.example.com;
}

protected-servers/srv2.conf:
server {
  server_name srv2.example.com;
}

This way I can enforce the servers in protected-server/*.conf to have
the googlebot check. Otherwise I would have to include a file in each
.conf file, which could lead to human mistakes.

Jaap
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20130116/8419c638/attachment.html>


More information about the nginx mailing list