Apache Virtual Host not accessible from local network - apache

I have setup a Virtual Host with Apache2 with the following configuration:
<VirtualHost *:8080>
ServerName example.com
DocumentRoot /var/www/example.com
</VirtualHost>
It is possible to access the website from the outside.
example.com
But if I enter example.com from another system in my local network, it opens my router configuration page.
I forwarded my routers port 80 to my servers port 8080 in my network.
But I would like to access the website as well from my other systems in the local network. Is this possible?

Your router probably does not support "NAT loopback", where you access a service on the local network via the WAN IP of the router. Most consumer grade routers do not support NAT loopback.
You only have 2 options:
Change your router to one that does support "NAT loopback".
eg. Which NETGEAR routers support NAT loopback
Access your service via the internal IP address instead. You can override the public DNS using your local HOSTS file.
The way I generally "work around" this and have the site accessible to all machines/devices on the LAN, is to define a local subdomain (A record) in the public DNS that points to the local IP address. So when on the LAN I access the site by the subdomain local.example.com instead.
Related question on Security SE, which goes into more detail about what actually goes on with the network traffic:
Is NAT Loopback on my router a security problem?

Related

Connect with public IP (ok) & Domain (not ok) EC2 Windows Instance

here is what I did so far:
I have setup a windows 10 instance
I assigned an Elastic IP
I added rules to the security group
HTTP TCP 80 0.0.0.0/0
Custom TCP Rule TCP 7474 0.0.0.0/0
MYSQL/Aurora TCP 3306 0.0.0.0/0
I assigned the public IP to the domain in the hosted zone as A record
I installed XAMPP 3.2.2
I made sure in httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
is active
In httpd-vhosts.conf I entered
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/my_app"
ServerName myapp.cloud
ServerAlias www.myapp.cloud
<Directory "c:/xampp/htdocs/my_app">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
I also changed hosts on the Windows Server (C:\Windows\System32\drivers\etc)
127.0.0.1 myapp.cloud
I rebooted the system
I started Apache via XAMPP Panel
Results:
I can access myapp.cloud local on the server with RDP session
I can access the public IP from outside and get the XAMPP screen
I can also access publicIP/my_app and get my application
A ping confirms that port 80 is obviously open (otherwise I wouldnt see the XAMPP screen as well)
I CANNOT access the application by typing myapp . cloud - this results in
ERR_CONNECTION_TIMED_OUT
Also Port 7474 seems NOT open although there is an entry
A port check (http://ping.eu/port-chk/) gives:
myapp.cloud:80 is open
myapp.cloud:3306 is open
myapp.cloud:7474 is CLOSED
Apparently the domain resolves correct as a DNS check returns the correct IP
So my issues:
Port 7474 isnt open although set in security
Cant access myapp.cloud although DNS seems right and port 80 is open and listens. (tested on FF and Chrome)
Any hints are very appreciated,
thanks.
######## EDIT ############# 09-11-2017
The problem of the unconnected IP is solved. It was a wrong DNS setting in my internal router - the router didnt renewed the IP settings. So Internet said DNS is correct but private network didnt - I flushed DNS on my PC but forgot to check the router and there was the problem.
Still struggling with the ports ..

Can't put WAMP online

UPD Provider's fault
I think I have read all the instructions and have done everything I could, but it still doesn't work :(
List of things I have done so far:
in httpd.conf file of the Apache server:
ServerName 192.168.0.102:8080
...
# onlineoffline tag - don't remove
Require all granted
...
Listen 0.0.0.0:8080
Listen [::0]:8080
Then I have the following result:
C:\Users\Sam>netstat -na | find ":8080"
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING
TCP [::]:8080 [::]:0 LISTENING
So, I guess, no firewall interruptions..
Then I have forwarded the thing in my TL-WR842ND router as follows:
In DHCP I set static local IP of 192.168.0.102 to my MAC and forwarded port 8080 to that IP. Then I rebooted the router but the port is still closed.
I can access WAMP though localhost:8080, through 192.168.0.102:8080, but cannot access remotely through the public IP. I also tried to set DMZ to 192.168.0.102 but that also had no impact. I called my provider and they said that they allow port forwarding and the problem must be on my side. pls help :(
Turns out, I have a common IP address with multiple other users and I have to pay extra to my provider in order to be able to expose services to the outside. I believe that is called a non-routable IP address.
You can read about it here

Multiple subdomains and servers behind single DynDNS name?

I've got a dynamic IP from my ISP so I'm using a free DynDNS service to redirect traffic to my server. I just bought a Raspberry Pi and would like to reach it from the outside too, preferrably with another subdomain. Can I use multiple CNAME records pointing at the DynDNS domain and then put a VHOSTS file in the servers to direct traffic to the right server depending on the subdomain called?
Or is it the DynDNS subdomain that calls the server rather than my own subdomain, i.e. showing the same id to the server independent of the subdomain called by the user? I'd rather not use different ports for different servers handling the same protocol.
Today:
server.example.com -> CNAME -> server.dyndns.com -> 1.2.3.4 -> home server
Future:
server.example.com -> CNAME -> server.dyndns.com -> 1.2.3.4 -> home server
rpi.example.com -> CNAME -> server.dyndns.com -> 1.2.3.4 -> raspberry pi
Ya I think you would just use CNAME records to point all of your sub domains to the same dyndns sub domain and then handle differentiating them all with vhosts. As for your raspberry pi, you might have to have a vhost on your apache web server that would act like a proxy server, sending all traffic from a hostname (sub domain) to the pi's ip. Here's an example of a vhost proxy configuration (goes in Apache's config, probably httpd.conf)
<VirtualHost *:80>
ServerName rpi.example.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
Replace localhost and port number with the ip and port of the raspberry pi

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

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/