I'm going to have 2 servers (SSO and application server) running on the same machine but listening on different ports. Is it possible to assign them following addresses: example.com and app.example.com so that the second would be a subdomain of the first?

How would I achieve this? would I use a hosts file or Active Directory?

I'm not going to use IIS. I want to test OpenAM product which will be deployed as Tomcat application (most likely listening on 8080 port), and I want to install OpenAM policy agent on Glassfish application server which will host some web application probably listening on 9090 port.
Now what I want to achieve is to redirect all example.com requests to and app.example.com to


You can have more than one website running on the same web server, using host headers / virtual hosts. This is a mechanism where the web server looks at the hostname the browser supplied (used to reach the web server) and serves content from the appropriate website.

You don't even need to define different ports for http websites if you define them each with unique host headers. If you'd rather have different ports then this is also pretty easy in most web servers (you don't say what web server you're using).

As for how to set up the names of the sites, this is also fairly easy, though its not really anything to do with active directory, and I wouldn't personally use hosts files for anything other than dev testing on a local webserver. You would simply create entries in DNS for the two website addresses, pointing to the web server.

So you'd create an "A" record for the hostname & IP address of the web server itself (e.g. mywebserver.example.com) and then use two "CNAME" records (aliases) that point example.com and app.example.com at that A record. This tells any client that looks up either of those two website addresses in DNS to use the IP address defined for the webserver itself.

update to address edit

There's no way to have port number included in in a host name or IP address. Your users will have to type in example.com:8080 and app.example.com:9090. What you're asking for is outside the scope of what can be done in DNS or hosts files because its not related to name resolution.

The two ways to get around that that I can think of would be

  1. To create two seperate virtual servers, each with the application installed on a webserver listening on port 80.

  2. Install IIS (or whatever) on port 80 and have a site for each host header there, as I describe above. Then use redirection from each site to the "correct" one listening at whatever port.

  • The problem is that, there will be 2 different servers running on the same machine, but listening on different ports. So I think it's not enough to just create 2 aliases which would redirect to the same server. What I want to achieve is to point example.com to and app.example.com to – jFrenetic Nov 19 '11 at 11:39
  • @jfrentic - updated answer to address your edit and comment to me. Your edit changes the scope of the question quite a bit! – Rob Moir Nov 19 '11 at 12:19

You can either use your hosts file or your dns server, whichever is easiest, usually hosts unless you need to have the servers available from outside your machine.

As you mention Active Directory I'm going to assume you're using Window/IIS in which case the actions you'll need to take are:

  1. Populate your hosts file / DNS server with example.com and app.example.com pointing to the appropriate IP address (Note: You can assign different IP addresses to each domain name and have your machine have multiple IP addresses, should you wish)
  2. Configure multiple websites in IIS Manager and apply a host-header binding to each of them.

If it is indeed the case that you're hosting these within IIS, you can have them both listening on port 80, should you choose as IIS will direct the traffic to the appropriate site depending on what host-header iot comes in on, i.e. example.com or app.example.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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