Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Im running an Apache2 webserver on a local network.

I can access it through http://myserver/ . I have multiple web applications in their folders on server, so when I want to access app1 or app2 I put http://myserver/app1 or http://myserver/app2

I'd like to setup my server in a way I might be able to access applications like http://app1.myserver or something nice like that.

I bet in order to achieve this I need to setup a local DNS server or tinker with something like mod-rewrite. What approach would you choose? I have experiences with neither DNS server nor mod-rewrite.

Thanks for your answers.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Dns is useful to propagate names over the network. So, yes, if you want to have app1.myserver transformed into <192.168.1.1>, you need a DNS server. But, if you are the only person using this (or for testing purpose), you can simply modify the hosts files on your local computer and add an entry for

192.168.1.1 app1.myserver

Now, if you have 3 applications: app1.myserver, app2.myserver and app3.myserver. When you connect to one of them using http://app1.myserver, you browser sends an HTTP request that contains a "Host" Header. This Host header has the value "Host: app1.myserver".

Apache receives your HTTP request, looks at the Host header, and direct the request to the good application. This is called Virtual Hosting,and this is what you do when you create Apache's virtual hosts.

So, you don't need mod_rewrite, a basic Apache2 server, and a local Host file (or a DNS) and you're all set.

share|improve this answer

Possible Solution:

As you describe the scenario (local development at home) the quickest way is to set up manually a DNS entry in your machine. This way you avoid setting up a DNS server. (Why expend 2 hours setting a DNS when you can have it in 2 mins...)

You have to manually add an entry to Hosts files on all the machines in your network (that I guess is your server and your computer). If your server is 192.168.0.10 and your local machine is 192.168.0.9

You have to add an entry in both machines similar to:

  • 192.168.0.10 app1.myserver
  • 192.168.0.10 app2.myserver

This way when you can access to your apps as http://app1.myserver or http://app2.myserver

How to do it?

  • If the machine is windows you have to add entry in C:\Windows\system32\drivers\etc\hosts
  • If it's a Linux go to /etc/hosts

Here you have more info for different OS: http://en.wikipedia.org/wiki/Hosts_%28file%29

share|improve this answer
    
I know about this option, but the fact is that I have multiple PCs that access my server and this would require to manually edit host files on each. Anyway, thanks for your answer. –  NumberFour Oct 3 '10 at 10:49

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.