Thursday, September 6, 2012

Redirect Incoming and Outgoing requests from/to Apache Server to/from Apache-Tomcat

I do not want to be recursive but i believe this can be usefull for someone(newbies)  as it was for me in the time that i needed.

Most of you can ask a question, why am i writing this post in English,  well, in fact there is only one reason, i speak portuguese all day long.

That's it...Jumping to the post...., shortcuting the to the results, let's go:

Redirecting incoming from Apache to Tomcat and vice-versa


Description:

There is a request to provide an application to internal users of an Enterprise. This enterprise uses his Data Center which is the core of all applications and services they provide to internal users and customers. The DC follow the standard like three tier architecture. But for this specific situation, we are going to use the following assumptions.

Assumptions: 

  • The Presentation Layer is based on Apache Server 2 which provide html pages to the users
  • At application layer we have a Apache-Tomcat 7 Application Server hosting the application like Asset Management
  • Both Apache Server and Apache-Tomcat are running on same server on top of Solaris 10 OE
  • Both Apache Server and Apache-Tomcat are installed following default configuration (no customization, no server hardening) and Proxy Modules are loaded: 
LoadModule proxy_module libexec/mod_proxy.so
LoadModule proxy_connect_module libexec/mod_proxy_connect.so
  • The access to the Apache Server is based on the following url: webcolab.nettech.co.mz
  • The url provided by the application is webcolab.nettech.co.mz:8080/assetmanagement

Problem Definition:

The url which was published to the company to access this application is webcolab.nettech.co.mz, which leads us to reconfigure the apache server to redirect the incoming request from webcolab.nettech.co.mz (default port is 80) to a content directory /assetmanagement on webcolab.nettech.co.mz on port 8080, default for Apache-Tomcat.

Solution:

First, we need to understand that Apache Server is listening on port 80 and the application Server open a session on port 8080 to provide the application. We do not want to change default settings for future hosting in the same environment:

  1.  edit the core configuration file of the Apache Web Server with your favorite text editor:
bash-3.2# vi /etc/apache2/httpd.conf

and add at the end of the file the following directives:


NameVirtualHost webcolab.nettech.co.mz:80

 < VirtualHost  webcolab.nettech.co.mz :80 >
     
        ServerName webcolab.nettech.co.mz
        proxyPass   /     http://webcolab.nettech.co.mz:8080/assetmanagement
        proxyPass   /     http://webcolab.nettech.co.mz:8080/assetmanagement
        ErrorLog      /var/apache2/logs/assetmanagement-error_log
        CustomLog  /var/apache2/logs/assetmanagement-access_log common

< /VirtualHost >




2.        Then restart the apache service like:

bash-3.2#  /usr/apache2/httpd –k restart 

Now, the resquest for application will be handled by the Apache Server on default port like 80 and using proxy reverse it will pass and reverse the requests to the Apache-Tomcat on port 8080 and vice-versa.

References: