Ugacomp

How to Configure Resource Limits in Apache Virtual Hosts

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM

CLOUD VPS M

$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM

CLOUD VPS L

$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

Configuring resource limits in Apache virtual hosts involves setting directives that control the amount of server resources allocated to each virtual host. This can help prevent a single virtual host from consuming excessive resources and impacting the overall server performance. Below are the steps to configure resource limits in Apache virtual hosts:

Enable mod_cgid or mod_cgi:

Ensure that the mod_cgid or mod_cgi module is enabled in your Apache configuration. This module is responsible for executing CGI scripts and is required for setting resource limits.

  • Use the following command to enable mod_cgid module:
   a2enmod cgid
  • Or, you can use the following command to enable the mod_cgi module:
a2enmod cgi

After enabling the module, restart Apache:\

systemctl restart apache2 

Configure Resource Limits


Open the Apache configuration file for the specific virtual host you want to configure. This file is typically located in the /etc/apache2/sites-available/ directory.

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html/example

    <Directory "/var/www/html/example">
        Options +ExecCGI
        AddHandler cgi-script .cgi

        LimitRequestBody 1048576
        Timeout 30
        MaxRequestWorkers 150
        MaxConnectionsPerChild 100
        RLimitCPU 10
        RLimitMEM 1048576
        RLimitNPROC 50
    </Directory>
</VirtualHost>

Here are some commonly used directives for resource limits, along with their explanations:

LimitRequestBody

This sets the limit on the size of the request body:

LimitRequestBody 1048576  # Limit request body to 1 MB

Timeout

This sets the maximum time, in seconds, that the server will wait for a request to complete:

Timeout 30  # Set the maximum request processing time to 30 seconds

MaxRequestWorkers

This sets the maximum number of simultaneous connections that will be processed:

MaxRequestWorkers 150  # Set the maximum number of simultaneous connections to 150

MaxConnectionsPerChild

This sets the maximum number of connections a child process will handle before it is terminated and replaced with a new one.

MaxConnectionsPerChild 100  # Set the maximum connections per child process to 100

RLimitCPU and RLimitMEM

This limits the CPU time and memory a process can consume:

RLimitCPU 10  # Limit CPU usage to 10 seconds
RLimitMEM 1048576  # Limit memory usage to 1 GB

RLimitNPROC

This limits the number of processes a user can create:

RLimitNPROC 50  # Limit the number of processes to 50

Restart Apache

After making changes to the Apache configuration, restart the Apache web server to apply the changes:

   systemctl restart apache2 

Verify that the virtual host is working correctly, and the resource limits are enforced.

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.
 

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.