I have a web server running inside vagrant virtual machine on my host machine (A). I want another machine (B) to be able to view a website over the LAN.
In my vagrant config I have the following relevant lines of config:
config.vm.network "public_network", ip: "192.168.33.10"
config.vm.network "forwarded_port", guest: 80, host: 8080
In my windows hosts file on host machine (A) I have:
192.168.33.10 awesomewebsite.dev
In the hosts file of the LAN machine (b) I have it pointed towards the IP of machine A
172.123.12.12 awesomewebsite.dev
I have an apache vhost file inside the VM with the following config:
<VirtualHost *:80>
ServerName awesomewebsite.dev
DocumentRoot /var/www/awesomesite
ErrorLog ${APACHE_LOG_DIR}/awesome.log
CustomLog ${APACHE_LOG_DIR}/awesome.log combined
</VirtualHost>
When I visit awesomewebsite.dev on host machine, it works. But when I visit on machine B it doesn't appear to reach machine A. When I visit awesomesite.dev:8080 on machine B it ends up in the wrong web directory and gets permission errors.
I have added the following (just for testing, i know its not high security)
<Directory "/var/www">
Allow from all
</Directory>
I need machine B to access the VM on machine A via the exact virtual host without the port. Is this possible?
with a public network it should just work with the following
192.168.33.10 awesomewebsite.dev
on the Machine B. This machine should be able to see any VMs running on host A and treat it as a separate machine (it is registered on the network with its own network interface)
You then do not work to do any forwarding port when working with static IP as you can just access any port directly from the IP
Related
I want to access my virtual hosts (websites) that I've set up in my VirtualBox -> Ubuntu-Server 18. I have apache2 installed and everything is setup.
The host machine (macOS) can presently gain access to the default website of apache2 in the guest (Ubuntu-server) through a Port Forwarding rule I have assigned in the VirtualBox Network Settings:
127.0.0.1:8000 -> 10.0.2.15:80
I've set up a virtual host in my guest machine with the following configuration:
<VirtualHost *:80>
ServerName dropn.taxi
ServerAdmin admin#dropn.taxi
DocumentRoot /var/www/dropn.taxi/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The DocumentRoot directory mentioned above exists and has the files necessary to serve a basic "Hello World" home page. I've tested it with my apache installed in my local machine as well. The website's not the problem.
But everytime I access localhost:8000 from the local machine, I'm greeted with an Ubnutu-Apache greetings page. Whereas when I try localhost:8000/dropn.taxi, I get a 404 page. I've researched quite a bit and the closest I can get to a solution is what is suggested in this page:
Ubuntu Apache2 local virtual hosts url not found
Simply put: How can I access virtual hosts of the guest machine (VM) from the host machine?
Still not specific to my case. Would appreciate any help in this regards.
localhost in the apache2 server is set to point to /var/www/html by default. For the virtual hosts to work properly, the domain name accessing them must be what is defined in the ServerName field.
localhost:8000/dropn.taxi would translate to 127.0.0.1/dropn.taxi in the VM guest. Which means, it is trying to access the /var/www/html/dropn.taxi, which, ultimately does not exist, hence the 404 error.
The solution to this is to add dropn.taxi to the /etc/hosts file in both the Host Machine and the VM. The line would look like:
127.0.0.1 localhost dropn.taxi
While accessing from the Host Machine, we use dropn.taxi:8000 in the browser whereas the port :8000 is not used in the guest machine. This way, whenever accessing the virtual hosts, the domain name accessing them matches the ServerName field and it simply works!
I'm running Ubuntu on vmware under windows 10, I set up and configured my apache to these configurations:
/etc/apache2/apache2.conf
<Directory /> ... stuff ... Require all granted </Directory>
VirtualHost1
<Directory ...>
....
AllowOverride All
Require all granted
</>
When I call the website from within the ubuntu on my vm it's reached fine, but when I call this site from my windows vm host machine my conn. gets refused.
This is my ubuntu hosts file:
127.0.0.1 test.com www.test.com
this is my windows hosts file
127.0.0.1 test.com www.test.com
**** All the listings here are approximate, so don't quote mistakes in code, apache restarts just fine
For all intent and purposes, a virtual machine is not the same as the host machine. Their network is totally separate.
If your virtual network is bridged, you need to access your ubuntu web server from it's public interface, usually eth0. This means, you will need to edit hosts file in windows to point www.test.com to the public ip address of ubuntu.
If your virtual network is NATted, you need to configure port-forwarding. I recommend using the same port numbers, if possible, for ease of use. You can keep the windows host table the same way you already have.
In both cases, the apache web server should listen on the public interface.
This depends on how you have configured you virtual host networking settings.
The 127.0.0.1 refers to you windows host on the windows machine and 127.0.0.1 refers to the ubuntu host on the virtual machine. The concept localhost (127.0.0.1) is always local host and should not leave the actual network interface (virtual or not). You need to contact you virtual host on virtually "external" ip-number from windows.
You can get the ubuntu ip-number by running "ifconfig" in a shell.
Best regards
Jørgen
I'm setting up a vagrant machine with a forwarded port.
config.vm.network "forwarded_port", guest: 80, host: 4567
I'm trying to access the site on port 4567 on my host machine, but I can only get the default /var/www/html/index.html from apache.
I set up in my hosts file /etc/hosts the site pointing to the local ip. And I have my site available and enabled in the apache of my vm to port 80.
What am I missing?
I fixed the issue finally. Just in case if someone has the same problem.
I changed in the virtual host configuration from
<VirtualHost site1.myserver.com:80>
to
<VirtualHost *:80>
ServerName site1.myserver.com
I have added a virtual host container in my httpd.conf file.
<VirtualHost *:80>
DocumentRoot /var/www/dev_sites/site
ServerName site.aa.local
</VirtualHost>
In my /etc/hosts file on my server computer it is:
127.0.0.1 site.aa.local
If I go to site.aa.local on my machine I can see my site. However if I go to that same address on another computer on my network it doesn't find the page. However, if I do aa.local it finds that. Any idea why a computer on my network can't see it?
I'm on a centos machine.
site.aa.local points to your loopback interface in your machine. Just in case: it's a virtual interface that is only accessible from your machine by definition.
For that name to work in another computer, site.aa.local should point to your machine's LAN IP address (either via /etc/hosts or DNS) and the Apache server in your computer should be listening in all interfaces (it most likely is).
Try adding YOUR_LAN_IP site.aa.local to the /etc/hosts file in the other computer, or just visit YOUR_LAN_IP if that is the Apache default virtual host (that is, if it's the only one or the first defined).
These two machines A and B are NAT behind 1 IP address.
Url.xyz.com goes to machine A on port 80 served by apache 2.2
and url2.xyz.com is supposed to go to machine B on port 80 served by apache 2.2 on that machine
i have machine A taking all inbound port 80 packets from my gateway...fyi
at one point i had apache on machine A setup to do this, but now i am struggling
to regain the good config. I am using a diff OS on a diff Machine B for good reasons....
i recall setting up virtual server url2.xyz.com in apache 2.2 on machine A using
port 80, then setting the host file on machine A and B to have a line titled:
192.168.0.x url2.xyz.com url2
and setting the document root for url2.xyz.com in apache on machine A equal to the document root on machine B. (it won't take a blank field....)
I am either dreaming, or missing a slight setup step. Any help appreciated. As I recall, from about six months ago, it seemed that apache on machine A read the host file and did this right..
the net good result is (hopefully) that the virtual server on machine A gets content from machine B (or C, or D, etc...)
alternatively i will try to get another Ip address from my provider.
One possibility is to have machine A act as a proxy for machine B. Meaning all requests for both domains go to machine A on port 80, but then you set up name based virtual hosts in apache. The virtual host for url2.xyz.com then forwards on the request to machine B.
Something like this:
Virtual hosts on machine A:
<VirtualHost *:80>
ServerName url1.xyz.com
DocumentRoot /var/www/url1
</VirtualHost>
<VirtualHost *:80>
ServerName url2.xyz.com
ProxyPass / http://url2.machineB/
ProxyPassReverse / http://url2.machineB/
</VirtualHost>
And then on machine A you define url2.machineB to point to the IP address of machine B. You do this by adding a line to the file /etc/hosts. Then on machine B you create an apache virtual host to listen for that domain, like so:
<ViirtualHost *:80>
ServerName url2.machineB
DocumentRoot /var/www/url2
</VirtualHost>
This might not be exactly the solution, but should give you one option to take. See http://httpd.apache.org/docs/2.2/mod/mod_proxy.html for more on proxying.