httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leif W" <>
Subject Re: [users@httpd] Blocking http requests to certain URLs.
Date Sat, 08 Jan 2005 07:23:28 GMT
>> Christopher J. Bottaro wrote:
>>I'm very new to Apache and web stuff in general.  Please bare with me.
>>I have my name server setup to route the following URLs to a single IP
>>I want Apache to reject http requests to and
>>  Currently (default Apache setup on Fedora Core 3), 
>>I can

>>put in my webbrowser "" and it will bring me to 
>>homepage.  I don't want that.
>>Thanks for your help.

What you are asking when you say "reject http requests" sounds like you 
want to disallow a connection at port 80 on your IP, but only if the 
Host header sent by the browser does not match  That 
is the functionality of a firewall at the application level as opposed 
to IP level or packet level.  Apache is a web server, not a firewall. 
Apache must Listen to the IP address and the port.  It can either listen 
or not listen, but not both.  If it doesn't listen, you can't use either.  If it does listen, it MUST accept the 
request.  Therefore you need to pay attention to what you have Apache do 
AFTER it inspects the request headers and looks at the Host header sent 
by the user agent (web browser, robot, etc.).  This means you need to 
use name based virtual hosting.  Read the documentation about NBVH.

> Aman Raheja; 2005 January 07 Friday 21:48
> It sure means you are listening on * and ServerName directive not 
> setup
> Be specific and use the Listen directive wisely, like
> Listen
> and use the same on your VirtualHost, if you have one and ServerName 
> directive be
> ServerName
> Then only will respond.
> Check apache docs for details on the directives.
> Aman Raheja

Exactly with some additional detail.  I would repeat the statement about 
reading the docs.  Use the "Directive Quick Reference" and look at the 
directives you will need to accomplish what you want to do.

DocumentRoot (your /public directory above)

With Apache, you need to Listen IP:PORT, regardless of the rest of the 
configuration.  With Name Based Virtual Hosting, you declare an IP:PORT 
to be used for name based virtual hosting.  This means that if a request 
comes to IP:80 on your machine, Apache knows that it must look through 
all of the available virtual hosts whose IP:PORT matches the 
<VirtualHost IP:PORT> directives.  For each matching IP:PORT, Apache 
must then see if the string in the Host header sent by the client 
matches the ServerName or any string in the ServerAlias list.  If the 
IP:PORT matches, but no ServerName or ServerAlias matches, then the 
first VirtualHost is used by default.

Depending on what you want to do, you need to set up at least 2 separate 
VirtualHost sections, or 3 if you want to isolate traffic with no Host 
header or a Host header that does not match anything.

Optionally, assuming that you want to isolate non-matching Host header 
(i.e. useful to put all those IP-based virus port probes into a separate 
file), then the first VirtualHost will be a dummy (ServerName default:80 
or dummy:80, no ServerAlias).  You create a separate directory, and 
serve a dummy index.html file, with no content (zero size), or a short 
note such as "This is not here."  You log access and errors separately.



After this the order of VirtualHosts does not matter as much.  But I use 
the convention that I put what I want first, then what I don't want 

The next VirtualHost section will be for the site that exists, and you 
want to serve,  You use a ServerName  You have your web page files and your log files in 
a separate directory, as outlined above, replacing "default" with your 
ServerName: /var/www/, etc.  This has nothing to 
do with Apache, just helps you remember which files belong to which 
website.  :)

Now, the final section holds one possible answer to your question.  The 
purpose is to capture and and do 
something useful with them.  Set the final VirtualHost's ServerName to 
one, and ServerAlias to the other.  Doesn't really matter which order. 
Just user ServerName host:80 and ServerAlias otherhost.  Now the Host 
header will match, and Apache will proceed to process the request from 
within this context.  What do you want to happen now?  Like the dummy or 
default site, you can chose to server a zero-size file, or a file with a 
short message.  However you probably want the user to be automatically 
sent to  This is handled by a very simple directive 
(Redirect), or a specific variation (RedirectPermanent).  You want to do 
a permanent redirect from / to .

Hey now, some people might suggest skipping all of that, and using one 
VirtualHost with ServerName and ServerAlias and  But the problem with that is now 
you have other people and even robots indexing your site from three 
locations.  If you later try to do statistical processing (stats) on 
your site, you have to add together the three sites, and then subtract 
the people who access more than one location.  It can be a real 
headache, best to avoid.

Some people might also suggest skipping the first optional default, and 
the third, and do NOT add ServerAlias, or just simply skip the dummy 
default.  Then everyone who types in or into a web browser gets sent back to 
them.  This is great, if you only run this one web site.  But if you 
chose to run with similar and host names, and someone types in one of those, they 
get sent to and NOT, two unrelated 
sites.  This is not good.  The solution is not scalable.  The best 
advice is to do this little extra work from the beginning, even for one 
site, because you probably will add one or two more when you learn how 
easy it is, and because you will have to do it anyways when you add more 
sites, and if you didn't do it this way first, that's extra time to redo 
it a second time.  :-)


The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message