Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My Apache Server IP address is 192.168.1.100 and the Domain Name is test.local.

  • If a user types in the URL, say "http://test.local", then they should be allowed.
  • If a user tries to access "http:// 192.168.1.100" then they should be denied.

How can I accomplish this?

share|improve this question
up vote 5 down vote accepted

What you want to do is name-based virtual hosting, so something along these lines might get you started, I believe:

NameVirtualHost *:80
<VirtualHost *:80>
  <Location />
  Order deny,allow
  Deny from all
  </Location>
  # other configuration for default host...
</VirtualHost>

<VirtualHost *:80>
  # This is the one you would like visible
  ServerName test.local
  <Location />
  Order deny,allow
  Allow from all
  </Location>
</VirtualHost>

(I'm in a bit of a hurry, so there might even by typos in there, sorry.)

share|improve this answer
1  
I suggest adding an explicit _default_ VirtualHost entry. – gertvdijk Dec 20 '12 at 14:17

I can't comment but others have to be warned! The other answer by ulrich-schwarz is very dangerous as it causes all other .htaccess files to be ignored by apache thus leaving sensitive parts of your site wide open!

That answer should be REMOVED IMMEDIATELY!!!

specifically

<VirtualHost *:80>
  <Location />
  Order deny,allow
  Allow from all
  </Location>
</VirtualHost>

will cause other .htaccess files to be ignored

share|improve this answer
1  
It's half-okay: this answer gives the reader no clues where the exact defect lies, and is not useful as it is written. – Thomas Dickey Nov 5 '15 at 22:52
    
@ThomasDickey I'm not concerned with why, only that it is clearly wrong. – user3338098 Nov 5 '15 at 22:53
    
@ThomasDickey And don't tell me preventing massive security holes is not useful. – user3338098 Nov 5 '15 at 22:53
1  
Writing these comments also is less useful than clarifying your answer. – Thomas Dickey Nov 5 '15 at 22:54
    
??? then why are you commenting in the first place ??? – user3338098 Nov 5 '15 at 22:56

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.