How to configure Subdomain in Tomcat for localhost?

UPDATED: 22 February 2014
In my previous article How to configure Subdomain in Tomcat 7? , I wrote about configuring subdomain on live server with linux environment. Today I'll show how you can configure sub-domain in Apache in local system with Netbeans and without Netbeans environment.

Configure sub-domain using Netbeans environment. 
Netbeans executable bundle has Apache Tomcat server in it. You can install Apache tomcat separately add it to Netbeans. So lets check out how to create sub-domain...

Step 1: Open Services tab in Netbeans. If you can't find click on Window > Services (Ctrl + 5) .

Step 2: Navigate to Servers > Apache Tomcat > Edit server.xml

Step 3: Find an Engine tag and add following line with in Engine tag.
<!-- Changes required in following code. In this example ( is my sub-domain and directory.
        1. appBase: sub-domain directory location in webapps.
        2. name: sub-domain name you want. like(,
        3. docBase: Absolute path/location of your directory. -->
<Host appBase="webapps/cdn_2b48cl2gf97hytt58p8g" autoDeploy="false" name="" unpackWARs="true">
      <Context antiJARLocking="true" docBase="D:\Path_to_project\build\web\cdn_2b48cl2gf97hytt58p8g" path=""/>

How to forward domain request using hosts file?
Using hosts file you can forward any domain request to any IP address or hosts. We'll forward sub-domain request to localhost.

Note: For this example I used windows platform. Use sudo vim /etc/hosts command in terminal for linux and mac OR

Step 1: Navigate to folder C:\Windows\System32\drivers\etc.

Step 2: Open hosts file using any editor like notepad and add line like below. So now your sub-domain will point to localhost.

How to setup sub-domain in Tomcat without Netbeans environment?
I gave you example to create sub-domain using Netbeans but technically you are using Netbeans as an editor nothing else. All you need to do is open server.xml file of your tomcat server in any editor like notepad follow same steps above and you are done.

Finally you need to restart your server and you are done!. Now you can access your sub-domain by url like You need to specify your tomcat server port.