Forward the Apache Server request to Tomcat Container

Post date: Apr 9, 2011 1:12:40 PM

Scenario:

I have use Apache Web server, it was listening on port 7777, if any request came from port:7777 means i need forward that request to another web container (Tomcat) which is listening on port:8080.

Solution:

Open the Apache Software installation folder, in my machine it was installed on following path

C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra

Here you will find the httpd-vhosts.conf file, this is the we need to configure in order to diver the request,

httpd-vhosts.conf file contain following information

#

# Virtual Hosts

#

# If you want to maintain multiple domains/hostnames on your

# machine you can setup VirtualHost containers for them. Most configurations

# use only name-based virtual hosts so the server doesn't need to worry about

# IP addresses. This is indicated by the asterisks in the directives below.

#

# Please see the documentation at

# <URL:http://httpd.apache.org/docs/2.2/vhosts/>

# for further details before you try to setup virtual hosts.

#

# You may use the command line option '-S' to verify your virtual host

# configuration.

#

# Use name-based virtual hosting.

#

#NameVirtualHost *:80

LISTEN 7777

NameVirtualHost *:7777

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for all requests that do not

# match a ServerName or ServerAlias in any <VirtualHost> block.

#

<VirtualHost *:80>

    ServerAdmin webmaster@dummy-host.greateindiaclub.com

   DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.greateindiaclub.com"

    ServerName dummy-host.greateindiaclub.com

    ServerAlias www.dummy-host.greateindiaclub.com

    ErrorLog "logs/dummy-host.greateindiaclub.om-error.log"

    CustomLog "logs/dummy-host.greateindiaclub.com-access.log" common

</VirtualHost>

Here  we said to container please listen port 7777

LISTEN 7777

NameVirtualHost *:7777

when request come for this port please forward the request to port 8080

<VirtualHost *:80>

    ServerAdmin webmaster@dummy-host.greateindiaclub.com

   DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.greateindiaclub.com"

    ServerName dummy-host.greateindiaclub.com

    ServerAlias www.dummy-host.greateindiaclub.com

    ErrorLog "logs/dummy-host.greateindiaclub.om-error.log"

    CustomLog "logs/dummy-host.greateindiaclub.com-access.log" common

</VirtualHost>

if i requested for http://localhost:7777/SampleXML/Books.xml to Apache server

means it internally forward that request to

http://localhost:8080/SampleXML/Books.xml which is running on TomCat.