Localhost is not going to the desired VirtualHost

I have several VirtalHosts installed on my computer. I would like to visit the site I'm currently working on from a different PC using my comp ip address, but every configurator I checked allows me to go to a different virtual host (actually the first virtual host I installed on my computer). How do I set up apache virtualhost configs to ensure that the ip address takes me to the site I want.

/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>

      

Any help would be appreciated.

Also, I don't know too much about setting up web servers and I used the tutorials to get the above code.

+2


a source to share


3 answers


Apache 2.x Virtual Hosts

1) This is required before the 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 element and a ServerName:

<VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example1.com

# Other directives here ...

</VirtualHost>

      

+2


a source


Make sure named virtual hosts are enabled. Then, from another computer, you need to set the hosts file so that it will go to the server's IP when these two domains accessed them.

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 cannot use name based virtual hosts if you want to access via IP, you need multiple IPs for that and set each virtual host for each IP, for example



<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 does not specify a name, it uses the first named virtual host configured.

+1


a source


add it to / etc / hosts:

127.0.0.1 theothersite.com

      

0


a source







All Articles