0

I'm using Apache HTTPD Server under Debian Squeeze.

How can I prevent users to access my server by the server hostname(dummy.xxx.com) or ip address(xx.xx.xx.xx)?!

For example: I do not want them to use the hostname or ip address as url. I already thought about using mod_rewrite for this, but is there another alternative?

Thanks!

Update:

Let me explain my thoughts with an example: Normally you can access the apache webserver htdocs by typing the ip address of the server or the server hostname or an registered domain. But I want to allow only access with the domain.

  • What type of system you are using? – B14D3 May 29 '12 at 07:14
  • What is it you are trying to achieve? If you don't want people to access to access your site at all simply shut down the web server. But I guess that's not what you're after. Please explain. If you want to allow access to (a part of) a website only to specific address you can use the [mod_access module](http://httpd.apache.org/docs/2.0/mod/mod_access.html). – Bram May 29 '12 at 07:24
  • @B14D3 I'am using apache httpd server under Debian Squeeze – Matthias Reisner May 29 '12 at 08:07
  • @Bram I have registered 2 domains which will be used to access my websites. So there is only the option to use the domains for the user but not the hostname or ip. – Matthias Reisner May 29 '12 at 08:07
  • This question is substantially similar to [How to block Spiders / Scrapers by REMOTE hostname / domain for all Virtual Hosts in Apache?](http://serverfault.com/questions/338830), but I don't think close enough to be closed as a dupe. – Chris S May 31 '12 at 19:54

3 Answers3

3

How can I prevent users to access my server by the hostname or ip address?! Then you want to block completely your site for some hosts. (or am I missing something?)

Best way to block users from some hosts is to use iptables of course if you are using linux or pf on bsd.

For example: (iptables) BLOCK_THIS_IP="x.x.x.x"

iptables -A INPUT -s "$BLOCK_THIS_IP" -j DROP

EDIT:

After update your question (in comment, please correct that and update your question) we know that you dont want do block your site but only restrict access for some users.

You can still achive this by making iptables rule but simpler way will be to restrict access making proper .htaccess file. Here is nice guide how to use .htaccess and restrict access with it.

http://www.javascriptkit.com/howto/htaccess5.shtml

http://perishablepress.com/stupid-htaccess-tricks/#sec7

B14D3
  • 5,188
  • 15
  • 64
  • 83
  • This presupposes that the OP is using a system that has iptabes which isn't obvious from the question. – user9517 May 29 '12 at 07:23
  • @lain thats why a asked about that in comment – B14D3 May 29 '12 at 07:57
  • I have updated my first post! Let me explain my thoughts with an example: Normally you can access the apache webserver htdocs by typing the ip address of the server or the server hostname or an registered domain. But I want to allow only access with the domain. – Matthias Reisner May 29 '12 at 08:15
  • @Matthias Reisner update your question not add comment. – B14D3 May 29 '12 at 08:22
2

You can do this by implementing a firewall and adding rules, for *NIX check B14D3's answer. On windows you can use the Software Configuration Wizard.

Lucas Kauffman
  • 16,880
  • 9
  • 58
  • 93
1

Set up a specific VirtualHost for the hostname you don't want people to use, and make it the default (so it will also catch requests for the IP-address); then, point the DocumentRoot at an empty-directory, or just return a 404, or similar.

nickgrim
  • 4,466
  • 1
  • 19
  • 28
  • Hmm, good idea. I wish apache could just solve all of my network security problems. Like send all bogus VNC connections and ssh attacks to some lame webpage.. that'll fool them! – mralexgray Jun 01 '12 at 09:46