Apache Virtual Host accessed by other machines in LAN
Environment
This is tested on Ubuntu 13.04 that running on VMWare Fusion 5. Host machine is MacBookPro that running Mavericks.
Most of the time in our development, we have to work on different projects.
We have to setup virtual host for every project.
Scenario
In this case is we have 2 projects that used the same port number. foo project & bar project.
Later a software tester will need to test the project on his own machine.
Machine A
has the IP 192.168.1.12. Machine B
has the IP 192.168.1.13.
In Machine A
(server machine that hosts all projects)
i.e. Add files to /etc/apache2/sites-available/
1 | <VirtualHost *:80> |
and
1 | <VirtualHost *:80> |
Activate the virtual host
1 | $ sudo a2ensite foo.com |
Edit the hosts file /etc/hosts
, add the following lines
1 | 127.0.0.1 local.foo.com |
In Machine B
(client that want to test the projects)
Edit the hosts file /etc/hosts
, add the following lines
1 | 192.168.1.12 local.foo.com |
(local.foo.com
and local.bar.com
is ServerAlias
)
Testing
For Machine B
, open up the browser, and type in the URL local.foo.com will see the foo
site; and local.bar.com will see the bar
site.
Reference: Apache Virtual Host (Subdomain) access with different computer on LAN