Nginx: Prevent DoS by limiting worker processes/connections

denial-of-servicenginx

If I limit my nginx worker processes to 1 and allow for 500 connections, what happens if I exceed this limit? Does the server return a 503 Service Unavailable?

Basically, I'm trying to secure my system against DoS and do not expect more than 500 simultaneous connections per second.

Best Answer

How many cores your server has ? If you have two cores, i suggest you can set 2 workers and 250 conn. max.

max_clients = worker_processes * worker_connections

And Yes, the 501 connection will receive an error. But be carefull, a browser opens 2 connections by default.

EDIT: One more thing, you can set a max connection limit by IP (10 here) with

## Max conns for one ip
 limit_zone gulag $binary_remote_addr 5m;
 limit_conn gulag 10;

in /etc/nginx/nginx.conf

Related Topic