Reputation: 978
I have several VirtalHosts set up on my computer. I'd like to visit the site I'm currently working on from a different PC using the my comp's ip address, but every config i've tried keeps taking me to a different virtual host (in fact the first virtualhost I set up on my comp). How do I set up the apache virtualhost configs to ensure that the ip address takes me to the site I want it to.
/etc/apache2/sites-available/site-i-want-to-show-up-with-ip-address.conf contains:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerAlias currentsite.com
DocumentRoot /path/to/root/of/site-i-want-to-show-up
ServerName localhost
ScriptAlias /awstats/ /usr/lib/cgi-bin/
CustomLog /var/log/apache2/current-site-access.log combined
</VirtualHost>
And /etc/apache2/sites-available/site-that-keeps-showing-up.conf contains:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerAlias theothersite.com
DocumentRoot /path/to/it
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
</VirtualHost>
I'd appreciate anyone's help.
Also, I don't know too much about configuring web servers, and I used tutorials to get the above code.
Upvotes: 2
Views: 4504
Reputation: 4217
Make sure named virtual hosts are on. Then from the other computer, you need to set the hosts file so that it will go to the IP of the server when those two domains are accessed.
ip.addr.x.y currentsize.com
ip.addr.x.y theothersite.com
# ip.addr.x.y is the ip of the pc with apache, this file goes on your other pc
You can't use name based virtual hosts if you want to access via IP address, to do that you'd need multiple IP's and set each virtual host to each IP, like
<VirtualHost ip.addr.x.y:80>
# one of the two IP addresses bound to the pc with apache on it
</VirtualHost>
<VirtualHost ip.addr.x.z:80>
# the other of the two IP addresses bound to the pc with apache on it
</VirtualHost>
If the request doesn't specify a name, it uses the first configured named virtual host.
Upvotes: 1
Reputation: 42666
1) You need this prior to your VirtualHosts sections:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
2) Each section needs a DocumentRoot and a ServerName item:
<VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example1.com
# Other directives here ...
</VirtualHost>
Upvotes: 2