Making tomcat and Apache live on port 80

Recently we are getting request where the client want’s to access domain running on tomcat (which is running on port 8080) without the port number.

Above requirement can be met using the mod_proxy on apache. You can use the below-pasted rule on the virtual host to meet the requirement:

    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

ProxyPass will map a remote server location to a local path. In this case, every request done to the root directory will be redirected to localhost at port 8080. Apache HTTP server will be simply mirroring the requests and responses from the client to the remote server.

ProxyReverse will adjust the headers from the remote server to match the locations expected by the client.

You have to add the aforementioned rule on virtual host. Please note that this has to be added to “Pre Main Include” or “Pre VirtualHost Include”. (FROM WHMHome »Service Configuration »Apache Configuration »Include Editor ) otherwise, apache rebuild will clear the entries.

Please refer the below code for a sample virtual host entry:

#DocumentRoot /home/trainee3/public_html
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/ 
ServerAdmin [email protected]
UseCanonicalName Off
CustomLog /etc/apache2/logs/domlogs/ combined

CustomLog /etc/apache2/logs/domlogs/ "%{%s}t %I .\n%{%s}t %O ."

## User trainee3 # Needed for Cpanel::ApacheConf

UserDir disabled
UserDir enabled trainee3

# Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
# To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
# the user's .htaccess file.  For more information, please read:

SSILegacyExprParser On

suPHP_UserGroup trainee3 trainee3

SuexecUserGroup trainee3 trainee3

RMode config
RUidGid trainee3 trainee3

# For more information on MPM ITK, please read:
AssignUserID trainee3 trainee3

ScriptAlias /cgi-bin/ /home/trainee3/public_html/cgi-bin/

# To customize this VirtualHost use an include file at the following location
# Include "/etc/apache2/conf.d/userdata/std/2_4/trainee3/*.conf"

*Note: You can even add instead of localhost

If the client want’s to route only to the tomcat server and he want to serve with the apache. The below-pasted code can be used:

ProxyPass        /tomcat http://localhost:8080/tomcat
ProxyPassReverse /tomcat http://localhost:8080/tomcat

If you need any further assistance contact me @ [email protected] prefer hangout ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.