# Server\_group { } directive?

**URL:** <https://www.ruby-forum.com/t/server-group-directive/229644>\
**Category:** NGINX\
**Created:** [January 16, 2013, 11:59am UTC](https://www.ruby-forum.com/t/server-group-directive/229644 "2013-01-16T11:59:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaap\_Taal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@Jaap\_Taal](https://www.ruby-forum.com/u/Jaap_Taal)\
**Post date:** [January 16, 2013, 11:59am UTC](https://www.ruby-forum.com/t/server-group-directive/229644/1 "2013-01-16T11:59:56Z")

</div>

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](http://srv1.example.com);  
}

server {  
server\_name [srv2.example.com](http://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](http://srv1.example.com);  
}

protected-servers/srv2.conf:  
server {  
server\_name [srv2.example.com](http://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
