Block Apache visiting from abnormal User-Agent?

My site is being attack by some abnormal client, with some invalid user-agent. They keep on scanning my server, and just keep on pushing up the server loading.

There is a lot of different defense method, and here is one of the simple solution (http://httpd.apache.org/docs/2.0/mod/mod_access.html). Just add the following lines (I just list those are required):

<VirtualHost *>
        # You need to add these line in regex formatting
        # Check your access log to find out those abnormal User-Agent
        SetEnvIf User-Agent .*www\.pingdom\.com.* robot
        SetEnvIf User-Agent .*blogspot\.com.* robot
        SetEnvIf User-Agent ^$ robot

        <Directory /var/www/>
                AllowOverride None
                Order allow,deny
                allow from all
                # Here we get the defined variable, and block them
                deny from env=robot
        </Directory>
</VirtualHost>

And so Apache will happily block those unfriendly user agents ;-)


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <code> <del> <blockquote> <q> <sub> <p> <br> <ul> <ol> <li> <dl> <dt> <dd> <a> <b> <u> <i> <sup> <acronym> <pre> <img>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.