Proxies, Free Proxies, Proxy Servers, CGIProxy, PHProxy, Proxy Sites, Proxy List and New Proxy Sites by ProxySphere
Proxies, Free Proxies, Proxy Servers, CGIProxy, PHProxy, Proxy Sites, Proxy List, and New Proxies by ProxySphere Link Auction Software
Home Proxies Top Proxies Articles Community Proxy KB CGIProxy PHProxy

Throttle Proxy Server Load with CGIProxy on Apache

  1. Introduction
  2. Requirements
  3. Download and Installation
  4. Configuration
  5. Testing

Introduction

mod_throttle is a powerful tool for Apache administrators and webmasters, and especially for proxy administrators searching for a way to keep a handle on all of that traffic. This article will take you step-by-step through setting up mod_throttle on your cPanel server and limiting traffic to prevent any more ugly down time.

Requirements

Before beginning this article, make sure your server meets the requirements for this particular configuration. The current available version of mod_throttle is designed to work with Apache HTTP Server Version 1.3, and there is no mention of 2.0 on the web site.

This article is written with cPanel users in mind, but the installation procedure should be the same for most GNU/Linux systems.

Finally, you will need permissions to install an Apache module on your server and edit your your htppd.conf files. Most likely you will need to be running a virtual private server (VPS), virtual dedicated server (VDS), or dedicated server. If you are on a shared host, ask your admin if the module is available or can be installed.

Now that we know the server is running everything we need, let's get started.

Download and Installation

Begin an SSH session to your web server (I recommend PuTTY). Once you are logged in, we can download mod_throttle and start configuring our web server.

# Change to your source directory, or wherever you want to extract. Usually /usr/local/src.
cd /usr/local/src

# Download the .tgz file.
wget http://www.proxysphere.com/files/mod_throttle312.tgz

# Extract the mod_throttle archive
tar zxvf mod_throttle312.tgz

If you would like to manually upload the file to your server, skip the line beginning with wget and download the file directly from Proxy Sphere:

mod_throttle312.tgz (41Kb) [Download]

If everything went smoothly, the archive has been downloaded and extracted to the server. The first thing we want to do is edit the Makefile. cPanel users can execute the following commands:

# Move to the directory that was just created
cd mod_throttle-3.1.2

# Run pico to edit the Makefile
pico Makefile

Find the following line in Makefile:

APXS=apxs

Change it to:

APXS=/usr/local/apache/bin/apxs

Now save the Makefile, exit pico, and run the following commands to complete the installation and restart your web server:

make
make install
service httpd restart

This is when I would usually go check to make my web site was still up and running. :) If everything looks okay, nothing disastrous has happened and mod_throttle should be installed as an Apache module. Now it's time to configure our restriction rules by VirtualHost.

Configuration

There are a wide variety of configuration options available for mod_throttle. We are going to learn how to define a basic mod_throttle parameter for VirtualHost containers in your httpd.conf file (in other words, how to use mod_throttle on a per-site basis), and we will cover some common configuration options for someone with a high traffic proxy site. For full details and configuration options, refer to the mod_throttle web site.

Note: mod_throttle provides multiple SetHandler options to let you view your throttle stats on your web site. throttle-status will list all of the web sites (VirtualHosts) on your server. If you are running multiple web sites on your server, you can use the throttle-me handler instead, which will only display throttle stats for that user. My recommendation is to use throttle-status on one user account / domain name for adminsitrator monitoring purposes, and use throttle-me for all of the rest to hide information about other accounts.

For any unique request, a hit is generated on our server, which is why proxies create so much demand on the resources. As such, a moderately trafficked proxy web site of say 15,000 visits per month could easily generate 2,000,000 requests. That's about 2,700 requests per hour, or nearly one request per second!

mod_throttle lets us define a limit and period to our policy. We will calculate our traffic usage using the Request policy. Since requests are validated by timeframe, we want to specify a short enough timeframe to avoid sporadic load. Preferably, we would like to calculate the number of requests quite often, so we don't end up with a large number of requests at one time, and then idle CPU cycles while people wait for the site to return. The busier the site, the more often you will want to refresh your throttle. We are using values of 15-30 minutes below, to ensure your site is up as much as possible, but doesn't get overloaded.

We will begin by editing the httpd.conf file and adding one of the following sections of code directly above the tag for the domain name you have selected. These options are generic configurations, and many more are available to customize your ruleset. ThrottlePolicy defines our policy for blocking web sites. Location defines the location of our throttle stastics page. SetHandler defines the type of stats we want at that location.

For a dedicated server: (4,000 hits per hour / 4M hits per month)


ThrottlePolicy Request 1000 15m


SetHandler throttle-me

For a VPS: (1,000 hits per hour / 1M hits per month)


ThrottlePolicy Request 500 30m


SetHandler throttle-me

For a low-end VPS: (500 hits per hour / 500K hits per month)


ThrottlePolicy Request 250 30m


SetHandler throttle-me

If you want to view stats for all of your web sites on a domain, but not implement any throttling, add the following code directly above the tag for the chosen domain:



ThrottlePolicy None


SetHandler throttle-status

Once you have added and saved your changes to httpd.conf, restart your web server and the changes should take effect:

service httpd restart

You will see that using these settings will give a 503 Server Busy message for any requests to that VirtualHost. It's easy to restrict this to a specific directory, so for example CGIProxy admins can set up throttling for their CGI file only, and this way their web site is still available when the limit has been reached on the CGI script.

To implement per-directory throttling, use the Directory container inside the appropriate VirtualHost and specify the target path in the directive. Taking from the last example, we would enclose our throttle directives with the Directory container:



ThrottlePolicy Request 250 30m


SetHandler throttle-me

Let's move on to testing our new configurations.

Testing

Obviously, the first step is to make sure your web sites still work! If nothing is broken in httpd.conf, you can test the throttle stats page right away:

For domains using throttle-me:
http://www.yourdomain.com/throttle-me
For domains using throttle-handler:
http://www.yourdomain.com/throttle-handler

You should now be finished with installing and configuring mod_throttle. At this point you should continue testing and optimizing the settings for your server. Feel free to ask us any questions or share your configurations in our forums.


boy million
ProxySphere is the place for proxies, free proxies, proxy forums, proxy servers, CGIProxy, PHProxy, working proxy sites,
info and much, much more! We focus on proxy information and resources for proxy users and proxy owners.