# Mapping domain



## hainguyen1402 (May 24, 2011)

Dear all,

I have built a Tomcat server with IP 192.168.1.225 and hostname abc.com. Whenever I want to access the Tomcat Server via a browser, I use http://192.168.1.225:8180 or http://abc.com:8180.

My problem is I need to access the Tomcat server with another domain name like http://tomcat.abc.com instead of http://abc.com:8180

Thank you all.


----------



## SirDice (May 24, 2011)

Simplest solution is to edit your /etc/hosts file. The more elegant solution is to run your own DNS.


----------



## hainguyen1402 (May 24, 2011)

Thank SirDice for reply

Let's me explain more: I have built successfully tomcat server with IP is 192.168.1.225 and I also have DNS server that configured domain name: abc.com to IP 192.168.1.225.

Whenever I need to access to tomcat server using browser, I have to use the port like http://192.168.1.225:8180 or http://abc.com:8180

Now, I need to map that when I access to tomcat server, instead of give port after address, I just access to http://tomcat.abc.com 

Please help me to solve it.

Thank so much.
p/s My DNS server is using djbdns.


----------



## biru (May 24, 2011)

you can use  apache with mod_jk in front of tomcat and setting your apache config / vhost config  with  .htaccess  using mod_rewrite on vhost document root but it's not easy. You must be a little bit tricky.


----------



## hainguyen1402 (May 24, 2011)

Biru, do you have any other suggestions. I just need to map from http://abc.com:8180 to http://tomcat.abc.com. Because my tomcat server is using for many application, I don't want to change much more about the tomcat configuration.


----------



## quintessence (May 25, 2011)

Hello,

This would be possible if tomcat.abc.com is for example IP: 10.0.0.1 and abc.com IP: 10.0.0.2. 

Then with firewall you can make rule for example: requests from everyone everywhere (or some private list) to 10.0.0.1 port 80, to be redirected to 10.0.0.2 port 8180.


----------



## SirDice (May 25, 2011)

quintessence said:
			
		

> This would be possible if tomcat.abc.com is for example IP: 10.0.0.1 and abc.com IP: 10.0.0.2.
> 
> Then with firewall you can make rule for example: requests from everyone everywhere (or some private list) to 10.0.0.1 port 80, to be redirected to 10.0.0.2 port 8180.


That's not possible.

But if tomcat is also bound to 127.0.0.1 you can redirect it to there.


----------



## quintessence (May 25, 2011)

Hello,

Which part is not possible?


----------



## SirDice (May 25, 2011)

quintessence said:
			
		

> Which part is not possible ?



Redirecting 10.0.0.1:80 to 10.0.0.2:8180 when both addresses are on the same interface.


----------



## bbzz (May 25, 2011)

Not on same interface; same host.


----------



## SirDice (May 25, 2011)

bbzz said:
			
		

> Not on same interface; same host.



Multiple interfaces on the same network subnet is not a good idea 

But, as I said, you can redirect 10.0.0.1:80 to 127.0.0.1:8180. If tomcat is bound to * (all addresses) then this should work.


----------



## bbzz (May 25, 2011)

Yeah any directly connected interface (loopback) can work.


----------



## quintessence (May 26, 2011)

SirDice said:
			
		

> Redirecting 10.0.0.1:80 to 10.0.0.2:8180 when both addresses are on the same interface.



Hello,

Well, actually it works.


```
rdr pass on lo proto tcp from any to 10.0.0.1 port 80 -> 10.0.0.2 port 8180
```

How correct is is other topic, IP addresses were just an example


----------



## AndyUKG (May 26, 2011)

Hi,

  I'm not 100% sure what you need to achieve, if you need to have tomcat listen on port 80 instead of port 8080 you can change this in tomcat's server.xml config file.

If you need to do anything more elaborate you can do it via mod_jk and Apache HTTPD as mentioned by biru. That would allow you to have the server use apache NameVirtualHost, add SSL etc. That requires an entry like this in the tomcat config:


```
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
```

and in the Apache HTTPD config something like:


```
# Load mod_jk module
LoadModule    jk_module  libexec/apache22/mod_jk.so
# Declare the module for <IfModule directive> (remove this line on Apache 2.0.x)
#AddModule     mod_jk.c
# Where to find workers.properties
JkWorkersFile /tomcat/conf/workers.properties
# Where to put jk shared memory
JkShmFile     /var/log/httpd/mod_jk.shm
# Where to put jk logs
JkLogFile     /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info
# Select the timestamp log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkMount  /* ajp13
```

tomcat/conf/workers.properties needs to exist, but if you don't have an existing file I think you can use a generic one, i.e. search for an example on google.

cheers Andy.


----------

