There's more...

Tracking connections via the client IP address isn't the only way we can limit connections. We can also set a limit for the server as a whole, which can be handy for preventing the server from being overloaded. Especially, where the system is behind a reverse proxy, this can be a simple yet effective way of ensuring that your website or application remains responsive.

To track for the server as a whole, we again first set the shared memory zone:

limit_conn_zone $server_name zone=serverlimitzone:10m; 

Then, we set our server directive:

server { 
    listen 80; 
    server_name limitcon.nginxcookbook.com; 
    access_log  /var/log/nginx/limitcon.log  combined; 
    location / { 
        root   /var/www/html; 
        limit_conn serverlimitzone 500; 
        index  index.html index.htm; 
    } 
} 

With this configuration, our server is limited to 500 concurrent connections. If there are more connections attempted, a 503 error will be returned to the client.