How do I access internal network virtual hosts in Apache?
As you have discovered, if you use the IP address of the server, you will be taken to the first virtual instance in the list.
I just add entries to my local hosts file that use the virtual server names.
Some xDSL routers (eg: Draytek's) will allow you to use URLS that refer back to sites hosted on the local LAN - this is called DNS loopback - so another 'fix' is to change the router. This can be a viable choice for, say, a business, where it's an easier to manage solution than updating all the local hosts files.
Related videos on Youtube
Mr Fox
Updated on September 17, 2022Comments
-
Mr Fox over 1 year
This might be a stupid question but I'm tired and can't find a solution.
I currently have an Apache Web Server running on Ubuntu 10.4 and I use a DynDNS service to make them accessible to the outside world via a domain and/or subdomain.
My configs currently look like this:
<VirtualHost *:80> ServerAdmin <obscured>@<obscured>.com ServerName <subdomain>.<obscured>.com ServerAlias <subdomain> DocumentRoot /<obscured>/<subdomain> <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /<obscured>/<subdomain>> Options Indexes FollowSymLinks MultiViews AllowOverride All Order Allow,Deny Allow From All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.$host.log CustomLog ${APACHE_LOG_DIR}/access.$host.log combined </VirtualHost>
This works fine from access outside of the network and all subdomains resolve to the correct directory.
The problem I am having is with accessing a subdomain over my internal network.
I can access the Web Server using the server's IP address:
http://192.168.1.123/
but this always takes me to the same virtual host and I don't know how to distinguish between different virtual hosts (different subdomains).Ideally I would like to access the same subdomains using
http://<subdomain>/
where<subdomain>
is the same as the subdomain attached to the external domain name.Any ideas?
-
Mr Fox about 13 yearsSorry I updated my question for clarification. It works fine externally.
-
Randolf Richardson about 13 yearsWhat is the private IP? Make sure Apache is listening on that too.
-
Mr Fox about 13 yearsUpdated again, I can access it using the IP directly but I don't know how to distinguish between different vhosts running different subdomains.
-
Randolf Richardson about 13 yearsHint: Check your "Listen" directive in the main httpd.conf file -- this needs to cover everything you need to serve on (specifying port 80 without an IP address should catch everything though).
-
Randolf Richardson about 13 yearsThe "ServerName" directive will take the main one. If you have additional hosts, then add a "ServerAlias" directive after that to support the additional ones in the same VirtualHost stanza/container.
-
Mr Fox about 13 yearsI tried adding
ServerAlias <subdomain>
but still nothing. -
Randolf Richardson about 13 yearsWhich IP address is your hostname resolving to? Is your VirtualHost actually configured to handle that IP address?