Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

As far as I can tell, there are two ways to access an Apache virtualhost on a server without a static IP address (i.e. my laptop):

  • Set the host name to foo.localhost in its Apache config file and assign fo.localhost to 127.0.0.1 in /etc/hosts. This makes them memorable but doesn't support clients on the LAN.

  • Listen to different ports. This supports clients on the LAN but makes them hard to remember.

Is there any way to host all virtualhosts on port 80 while making them accessible to other devices? Possibly a reverse proxy that routes 127.0.0.1:80/foo/theactualurl to 127.0.0.1:42908/theactualurl, 127.0.0.1:80/bar/anotherurl to 127.0.0.1:39539/anotherurl?

I'm running Ubuntu 12.04.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

I'm a beginner myself, but this came to mind... Can't hurt to try :)

Just set the ServerName directive to foo.localhost and use the ProxyPass to direct it to a LAN address.

Something like:

<VirtualHost *:80>
   ServerName foo.localhost
   DocumentRoot /var/www/foo  #doesn't matter because we're not going to hit it
   <Location />
      ProxyPass http://192.168.x.x/
      ProxyPassReverse http://192.168.x.x/
   </Location>
</VirtualHost>

Then your other internal site is accessed like:

<VirtualHost *:80>
   ServerName foo2.localhost
   DocumentRoot /var/www/foo2  #again, doesn't matter
   <Location />
      ProxyPass http://192.168.x.y/
      ProxyPassReverse http://192.168.x.y/
   </Location>
</VirtualHost>

I'll admit, I don't know if that'll work, but it seems reasonable to me ;)

Also, you didn't mention how many computers were on the LAN, but if it's only a few, maybe an edit to the /hosts file would be your solution.

share|improve this answer
add comment

Putting your applications in separate folder on the same virtualhost is not an option for you?

Another simple solution is to change all hosts files on the client PCs of your lan to add:

YOUR_SERVER_IP  foo.com bar.com

but it's not very handy if the IP can change because of DHCP.

With avahi/zeroconf on Ubuntu, PCs advertise themselves as HOSTNAME.local so you can use http://HOSTNAME.local to reach your local webserver. Maybe it's possible to add some new aliases with avahi.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.