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 want to tests to sites locally.

It is good for me to have two configuration sections in Apache.

I tried

<VirtualHost 127.0.0.1>
    ...
</VirtualHost>


<VirtualHost 127.0.0.2>
    ...
</VirtualHost>

But when I type in browser 127.0.0.2, it shows the page from 127.0.0.1.

What is wrong and how can I resolve the issue?

Possibly the common practice is to change hosts.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Put your fake domain names into your /etc/hosts file and use name-based virtual hosting.

# /etc/hosts
127.0.0.1    example.com example.org example.net

# Apache httpd VirtualHost configuration
NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
  ServerName example.com
  # [...]
</VirtualHost>

<VirtualHost 127.0.0.1:80>
  ServerName example.org
  # [...]
</VirtualHost>

<VirtualHost 127.0.0.1:80>
  ServerName example.net
  # [...]
</VirtualHost>
share|improve this answer

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.