Apache connection refused outside of localhost - apache

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

Related

How to access Virtual Hosts setup on the VM from the Host Machine?

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!

Access Vagrant VM via virtual host over LAN

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

Why Require directive does not work properly on Apache?

I have a virtual machine with Virtualbox in which I installed Ubuntu 14.04 and Apache. I am trying that only my host machine could access to this resource with Require directive.
I know that the connection between the virtual machine and the host machine it is correct because if I put on my host machine browser the url localhost:8080 I can see all the content of the root directory of Apache.
The problems comes when I try to use the directive Require on a directory inside the root directory. I only want that the host machine will have access to that resource so I add to the apache2.conf file these lines:
<Directory /var/www/example/>
Options Indexes FollowSymLinks
AllowOverride None
Require ip (Here the ipv4 of my host machine)
</Directory>
but I do not have access from my host machine to this resource.
What could be the problem?
Thanks in advance!
The VirtualBox NAT configuration you are using is causing the http request from your host machine to come into your virtual machine via an internal IP rather than the IP you are expecting. You'll need to update the Require directive to use this internal IP. To do this, check your Apache access logs to see the incoming IP when you access the resource. Use that IP in the require directive. You should see a line for each access request with the incoming IP & the resource accessed. You should see a line denying your access request when access is denied.

Accessing local Apache website from remote machine in same network

This is my story.
I installed Apache in windows 7 and configured Virtual host. Below is my directory tree.
D:\
Apache/
PHP/
MySQL/
projects/
and virtual host configuration.
<VirtualHost stuff.dev>
DocumentRoot "D:/projects/stuff"
ServerName stuff.dev
ServerAlias stuff.dev
<Directory "D:/projects/stuff">
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I also add host name in hosts file. I could accessed stuff.dev in local machine but I can't access from remote machine although I add host name in remote's hosts files.
When I access website from remote machine, It's always access to default host (htdocs/index.html).
How can I access local website from remote machine?
If you can access via localhost and not from your other computer, the issue is your Windows Firewall.... try to disable it or configure it to handle port 80
If Windows Firewall is disabled and still not working make sure you don't have any application (like Skype) that is conflicted with Apache port 80

can't see site on network but can see it locally

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).