limit connection based on Host header

Francis Daly francis at
Sat Feb 4 08:06:31 UTC 2017

On Fri, Feb 03, 2017 at 09:54:43PM -0800, Frank Liu wrote:

Hi there,

> I have a default "server" block with "server_name _ ;".  Since connections
> coming in may have different Host header, I am trying to limit the
> connection based on Host header.
> limit_conn_zone $server_name zone=perserver:10m;

$server_name is the primary server name, which is the first parameter
in the server_name directive.

The "host" header sent by the client is $http_host. A tidied-up version
of that (which could be populated from something else instead) is $host.

> It seems if the connection for one Host reaches 10, I see errors "limiting
> connections by zone "perserver" for connections with other Host as well.
> Did I miss anything?

Your configuration limits based on the server name. All requests to
one server{} have the same $server_name, so what you see is what you
asked for.


Francis Daly        francis at

More information about the nginx mailing list