Tomcat and httpd configured in port 8080 and 80

By: Emiley J Emailed: 1590 times Printed: 2040 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

When you install Tomcat in your server, by default it uses port 8080. Typically in a linux system, you can install apache2 or httpd as a web server that handles the default port 80 and then uses mod_proxy to send requests to Tomcat at port 8080 for sites hosted in Tomcat.

httpd (or apache2) are great for hosting multiple websites (multiple domains) in a single server. In this example, we will install, httpd in port 80 and Tomcat7 in port 8080 and then configure both of them to handle requests seamlessly.

Install and configure httpd

  • yum install httpdYou could ofcourse use apt-get instead of yum depending on your platform
  • vim /etc/httpd/conf/httpd.conf
    Look for the following modules and enable them if they are not already enabled
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so

    Then uncomment, the following line
    NameVirtualHost *:80

    Uncomment the following lines at the bottom and change it to point to your default domain.

    <VirtualHost *:80>
        ServerAdmin webmaster@yourdefaultdomain.com
        DocumentRoot /var/www/html
        ServerName www.yourdefaultdomain.com
        ErrorLog logs/default-error_log
        CustomLog logs/default-access_log common
    </VirtualHost>
    

    Save and close the file by pressing 'Esc' and the typing :wq! and Enter.
  • service httpd start

Intall and configure tomcat7

  • yum install tomcat7-webapps tomcat7-docs-webapp tomcat7-admin-webapps
  • under /etc/httpd/conf.d create a file named mytomcatapp.conf and copy the below code
  • <VirtualHost *:80>
    ServerName www.myanotherdomain.com
    ProxyPass         /  http://localhost:8080/
    ProxyPassReverse  /  http://localhost:8080/
    ProxyRequests     Off
    
    # Local reverse proxy authorization override
    # Most unix distribution deny proxy by default 
    # (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)
    <Proxy http://localhost:8080/*>
      Order deny,allow
      Allow from all
    </Proxy>
    </VirtualHost>
    

You have now installed both httpd and tomcat7 and configured them. You now have to start/restart both services

service httpd restart
service tomcat7 restart

Now when you goto your www.yourdefaultdomain.com in your browser, the request is direclty handled by httpd service and the index file from your /var/www/html folder will be returned to the browser.

If you goto www.myanotherdomain.com in your browser, the request will be forwarded by httpd service to the tomcat7 internally and your tomcat application will serve the pages.

The domains www.myanotherdomain.com and www.yourdefaultdomain.com are used for illustration purposes only. You have to use your own valid domains, and the DNS A records have to be created to point to the IP address of your server

Java Home | All Java Tutorials | Latest Java Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Emiley J
Password must include both numeric and alphabetic characters - Magento
What is Hadoop?
Returning multiple values from a web service
Tomcat and httpd configured in port 8080 and 80
Java Webservices using Netbeans and Tomcat
Java WebService connected to Database
How to Deploy a Java Web Service
Call a webservice in Java
Java WebService - Create your first web service in Java
package javax.jws does not exist
Getting Started with Android
HTML5 Location - getCurrentPosition() in HTML5
HTML5 Canvas - Using Canvas in HTML5
HTML5 - Introduction
HTML5 Video - Handling video in HTML5

More Tutorials in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java File
Java String
Count number of vowels, consonants and digits in a String in Java
Reverse a number in Java
Student marks calculation program in Java
Handling Fractions in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Multiple Inheritance sample in Java
Java program using Method Overriding
Java program to check if user input is an even number

More Latest News
Most Viewed Articles (in Java )
How to Send SMS using Java Program (full code sample included)
InetAddress Example program in Java
Using StringTokenizer in Java
Abstract classes in Java
wait(), notify() and notifyAll() in Java - A tutorial
Method Overriding in Java
How to use Iterator in Java
FileReader and FileWriter example program in Java
Recursion in java
How to use ArrayList in Java
XML and Java - Parsing XML using Java Tutorial
Vector example in Java
Method Overloading (function overloading) in Java
Garbage Collection in Java
Student marks calculation program in Java
Most Emailed Articles (in Java)
Understanding isInfinite( ) and isNaN( ) in Java
indexOf( ) and lastIndexOf( ) in Java
equals( ) Versus == in Java
valueOf() in Java
Simple Port Scanner application using Java
How to use Iterator in Java
How to use equals( ) and equalsIgnoreCase( ) in Java
Sample program to demonstrate the use of ActionListener
Using StringTokenizer in Java
ThreadGroup Sample in Java
Using toLowerCase( ) and toUpperCase( ) in Java
Using substring( ) in Java
How to use regionMatches( ) in Java
String Concatenation using Java
How to use ArrayList in Java