How can I access Apache name based vhosts from different device on my LAN?

I have Apache 2.2 setup with name based virtual hosts on my development computer but I want to access them from my phone/tablet.

Apache is running on my main computer at 192.168.1.123. Each local website is stored under htdocs like:
C:\Apache2\htdocs\dev.website1.net
C:\Apache2\htdocs\dev.website2.net
etc.

If I type 192.168.1.123 into the browser on my tablet I get a Not Found error message: “The requested URL / was not found on this server.”
In the Apache error.log it says:

[error] [client 192.168.1.107] File does not exist: C:/Apache2/htdocs/192.168.1.123

My Apache httpd-vhosts.conf is setup like:

NameVirtualHost *:80

<VirtualHost *:80>
   UseCanonicalName Off
   VirtualDocumentRoot "c:/Apache2/htdocs/%0"
   VirtualScriptAlias "c:/Apache2/%0/cgi-bin"
</VirtualHost>

Is it possible for me to access dev.website1.net from my tablet? It’s not rooted, so I can’t edit the Android hosts file.

Thanks

Sorry, it’s not clear here - but did you try “http://192.168.1.123/dev.website1.net”?

Yeah, it just gives the Not Found error page saying:

The requested URL /dev.website1.net was not found on this server.

But the error log entry still only says:

[error] [client 192.168.1.107] File does not exist: C:/Apache2/htdocs/192.168.1.123

If I create the folder in htdocs called “192.128.1.123” and put an index file in it then that IS displayed in the tablet.
So I guess the problem is due to the VirtualDocumentRoot directive… but is the only way to get around that editing the Andorids hosts file? Or is there a way to get around it using only Apache?

If memory serves, that %0 is a reference to the incoming servername - that’s why it’s constantly adding that IP to the end. If that’s true, you might be able to access your sites with ( http://192.168.1.123/dev.website1.net ) by removing that %0 and restarting apache.

However, this depends largely on your goals. How are you wanting to access the sites? Does it matter to you?

NameVirtualHost *:80
<VirtualHost *:80>
   UseCanonicalName Off
   VirtualDocumentRoot "c:/Apache2/htdocs"
   VirtualScriptAlias "c:/Apache2/cgi-bin"
</VirtualHost>

This looks like a bit out of a setup that would process different vhosts, but not a complete arrangement. If all you want is to access them via / then you may not need that.

I’m not an expert on Apache virtualhosts, by any means, might just wait for a better answer. In the meantime, try it without the %0 for kicks?

Edit: I can’t see why you’d need the android host file changed… this should be solvable in Apache config somehow.

I’m using mod_vhost_alias to do “dynamically configured mass virtual hosting” so that “adding virtual hosts is simply a matter of creating the appropriate directories in the filesystem and entries in the DNS - no need to reconfigure or restart Apache”. http://httpd.apache.org/docs/2.2/vhosts/mass.html

Removing the %0 makes it work from the tablet with 192.168.1.123/dev.website1.net
But then I have to also specify the IP to access it from the main computer running Apache e.g. 127.0.0.1/dev.website1.net
But having to include the IP makes the sites not work properly with my front controller and/or PHP stuff.

On my computer running Apache I edit the hosts file to point all my development sites to 127.0.0.1. The simple solution would be to edit the hosts file on my phone/tablet so that requests from them to dev.website1.net etc are sent to 192.168.1.123
Could it be done in my router somehow…?

I see what you’re saying… without the time to do research (at work) I’m at a loss for what you’d want to do though… if it’s not answered this evening I might take a look and see if I can find out anything helpful. Always nice to learn more about Apache and Nginx. They’re the bane of development existence while at the same time being the house we live in… kinda… heh.

On your remote device, add the virtual host to your hosts file using the IP address and the virtual host name. On the hosting computer, add it to your hosts file, too. What you need to do is simulate DNS settings to gain access to the file.

Regards,

DK