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 with several static IPs (127.0.0.1, 127.0.0.2, etc.). I'd like to make Apache only listen on the 127.0.0.1 IP address for every domain (virtualhosts).

I tried the following:

# No NameVirtualHost used
Listen 127.0.0.1:80

<VirtualHost one.domain.com>
...
</VirtualHost>


<VirtualHost two.domain.com>
...
</VirtualHost>

This didn't work as wanted as every virtualhost entry (and the IP) were pointing to the first VirtualHost entry.

Now I am using:

NameVirtualHost 127.0.0.1:80
Listen 80


<VirtualHost one.domain.com>
...
</VirtualHost>


<VirtualHost two.domain.com>
...
</VirtualHost>

But now Apache listens on every IP from the server.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Your first setup was correct in concept, wrong in implementation.

Listen 127.0.0.1:80
NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
  ServerName one.domain.com
  ...
</VirtualHost>

<VirtualHost 127.0.0.1:80>
  ServerName two.domain.com
  ...
</VirtualHost>
share|improve this answer
    
That's the solution, thanks. I also have to add that ServerName also needs to be set globally, otherwise Apache won't start, as happened with me. –  EarthMind Aug 21 '10 at 14:32
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.