On a hosting server, the number of simultaneous connections that a server can handle can be configured at different levels, depending on the type of web server and the environment it’s set up in. Below is a detailed guide on how to configure it for the most common web servers, like Apache, Nginx, and PHP-FPM:

1. Apache

Apache allows configuring the number of concurrent connections through its modules and directives in the main configuration file, usually located at /etc/apache2/apache2.conf or /etc/httpd/httpd.conf, depending on the operating system.

Key parameters:
  • MaxRequestWorkers: Defines the maximum number of simultaneous requests that Apache can handle.
    <IfModule mpm_prefork_module>
    MaxRequestWorkers 150
    </IfModule>
  • ServerLimit: Defines the maximum number of processes Apache can spawn.
    <IfModule mpm_worker_module>
    ServerLimit 256
    </IfModule>
  • MaxConnectionsPerChild: Defines the maximum number of connections each child process handles before being recycled.
    MaxConnectionsPerChild 1000

After making these changes, restart Apache with:

sudo systemctl restart apache2

2. Nginx

In Nginx, the configuration of simultaneous connections is mainly controlled through the following parameters in the configuration file located at /etc/nginx/nginx.conf:

Key parameters:
  • worker_processes: Defines the number of worker processes Nginx will run. This should align with the number of CPU cores on the server.
    worker_processes auto;
  • worker_connections: Defines the maximum number of simultaneous connections that a single worker process can handle.
    worker_connections 1024;
  • events: This section allows configuring event handling parameters, such as the I/O method used.
    events {
    worker_connections 1024;
    }

The total number of simultaneous connections Nginx can handle is the product of worker_processes and worker_connections.

Once the changes are made, restart Nginx with:

sudo systemctl restart nginx

3. PHP-FPM

If your web application uses PHP-FPM to handle PHP requests, you should configure the number of concurrent connections in the php-fpm.conf file or in the pool files, located in /etc/php/7.4/fpm/pool.d/www.conf (the path may vary depending on the PHP version).

Key parameters:
  • pm.max_children: Sets the maximum number of PHP-FPM processes that can run simultaneously.
    pm.max_children = 50
  • pm.start_servers: The number of processes that start when the service begins.
    pm.start_servers = 5
  • pm.max_spare_servers: The maximum number of spare (idle) processes.
    pm.max_spare_servers = 10

After making changes, restart PHP-FPM:

sudo systemctl restart php7.4-fpm