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

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

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!

Apache connection refused outside of localhost

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

Access to local webserver with XAMPP

I'm using local server where XAMPP is running on. This local server is in the same network as my own computer. Now I want to access different site's running on that server. I had the following in mind.
My local server IP is 10.0.0.2. In my own hosts file I added the following.
10.0.0.2 www.domain.nl
Now when I enter www.domain.nl in my browser, I will be redirected to the server's localhost.
At the server, I added a VirtualHost to the httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/domain
ServerName localhost
</VirtualHost>
So now I will be redirected to the website running in the folder domain.
The problem
The problem now is, I also have a other website running on the local server. This one is on
the local server located in c:/xampp/htdocs/anotherdomain.
Adding another virtualhost does now only work on the local server itself, but not remote, because from remote I will always have the ServerName localhost.
How will I set this up? Hope you all understand my problem and someone knows how to get this working.

how to Redirect two URL's on same port to two diff IP's internally

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.

How access Apache Virtual Host with a mobile device?

After setting up Apache virtual hosts with hostnames "server1" and "server2", how would I access them with my iPhone (or any mobile device) since there's no way modify the /etc/hosts file in iOS or Android?
My understanding is that you have to reference the virtual hosts by name (assuming you only have 1 IP address on your physical server), but there's no way to map those virtual hostnames to the single IP address on my physical server.
I'm running my server on my laptop using MAMP and my Vonage router/Apple Airport don't support DNS. Do I need to setup a local DNS server? Is there any easy way to run that on my laptop? Thanks.
Adding as following
httpd-vhosts.conf
<VirtualHost *:8080>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "/opt/lampp/htdocs/api/www"
ErrorLog "logs/app_error"
CustomLog "logs/app_log" common
</VirtualHost>
httpd.conf:
Listen 80
Listen 8080
Then in your mobile you can use:
http://<your laptop address>:8080/
You can't if you don't have a local DNS.
As a workaround, you could setup your first VirtualHost to listen on the 80 port and the second one on the 81 (or 8080 or whichever ports you want) and access the server by using http://your.server.ip.addr:port.
You could use IP aliasing and configure IP-based virtual hosts. But then you have to access the sites via IP from your mobile device. But I guess using different ports as #Renaud suggests is easier.
If you want to do it, add an IP alias using ifconfig <interface> inet <ip> add on Mac OS X. Then add a Listen <ip> and <VirtualHost ip> directive to your Apache configuration.
The below link has a nice work around for this problem.
Pleas go through this, after you have set the virtual host.
1.http://rocketmodule.com/blog/easy-and-free-way-test-local-sites-ipads-iphones-and-other-mobile-devices/
but instead of the path you need to give the local domain name. for example "king.dev" link below
192.168.1.250(your system ip) king.dev
in the hosts.ics file in your system.
now you can access the website from your mobile typing in your browser like.
192.168.1.250:4000[if you have set the port]/your_file.html
your local website will be displayed in the mobile device
you can also have a look at
http://www.tech-otaku.com/local-server/accessing-localhost-virtual-hosts-network-computer/