Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a server running Apache that often gets unwanted proxy requests, mostly for sites like www.yandex.ru or www.baidu.com. I don't have mod_proxy loaded, so these requests don't actually work. But what happens is that the content returned corresponds to the home page for my website, presumably because that's the default virtual host. The thing is, I'd rather not send back the full index page to someone who obviously isn't actually interested in my website; I consider it a waste of bandwidth and resources. I'd rather respond with an HTTP error code (400 I suppose) to signal that my server does not work as a proxy, and also to make myself feel better when I examine the access logs ;-)

What's the recommended way to configure Apache to return an error code for a proxy request? (By "proxy request" I mean one that provides an absolute URL in the HTTP request line.) And which HTTP error code is most appropriate for this?

By the way, I thought this would have been asked already but I looked and didn't find it.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You could simply configure a default vhost that denies all request:

<VirtualHost *:80>
  ServerName deny.all
  <Location />
    Order allow,deny
    Deny from all
  </Location>
</VirtualHost>

With that in place, all requests accessing a vhost that is not explicitly configure will be denied with HTTP error code 403 ("Forbidden").

Also be sure to have a look at the Apache wiki page on proxy abuse for more details. Beyond the solution above, they will also give you hints for a mod_rewrite-based solution.

share|improve this answer
    
Thanks, I figured it might be that, but I wanted to see if there were other ways to consider. (I'll accept this if nobody comes along with a better answer within a day or two) –  David Z Jul 15 '10 at 7:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.