Tomcat and httpd configured in port 8080 and 80

By: Emiley J Viewed: 154073 times  Printer Friendly Format    


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


Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial

Subscribe to Tutorials

Archived Comments

1. che, hale this adverts that are there in this web
View Tutorial          By: kelibone at 2015-03-06 08:10:29

2. Evaluating where you are based on three valuable s
View Tutorial          By: _____ at 2017-01-04 05:12:27

3. xrdfvm
View Tutorial          By: bgutecv at 2017-02-21 20:59:50

4. wqwgaw
View Tutorial          By: silxea at 2017-02-26 00:51:04

5. kqh98q
View Tutorial          By: xlxm00 at 2017-03-01 03:05:29

6. ksbhqj
View Tutorial          By: yfi16c at 2017-03-01 22:49:40

7. nulchx
View Tutorial          By: vkx76j at 2017-03-03 02:56:23

8. ewlx01
View Tutorial          By: prleln at 2017-03-03 06:07:15

9. ebxarrm
View Tutorial          By: gkxoot at 2017-03-08 10:13:01

10. viagra without a doctors approval
View Tutorial          By: viagra without a doctor prescription at 2017-03-13 09:22:07

11. fck39d
View Tutorial          By: btyg74 at 2017-03-29 21:26:12

12. kculol
View Tutorial          By: nnz51s at 2017-04-01 08:16:23

13. zyquah
View Tutorial          By: jkuq84 at 2017-04-02 01:56:13

14. ivs39w
View Tutorial          By: aufbvs at 2017-04-02 20:41:56

15. Myye62t
View Tutorial          By: Mgwkjra at 2017-04-02 21:12:44

16. wih69n
View Tutorial          By: lwmdvd at 2017-04-03 21:32:03

17. alqmwx
View Tutorial          By: rthrdi at 2017-04-04 19:12:17

18. cev32o
View Tutorial          By: eoy22f at 2017-04-07 00:36:42

19. orbi48
View Tutorial          By: mrcxyl at 2017-04-11 09:36:26

20. JasonNix
View Tutorial          By: JasonNix at 2017-04-13 08:43:50

21. elftvk
View Tutorial          By: jfgwaq at 2017-04-16 04:05:18

22. njinhs
View Tutorial          By: qagy28 at 2017-04-16 08:18:38

23. phci56
View Tutorial          By: dctukj at 2017-04-17 00:41:07

24. Iinujtyd
View Tutorial          By: Iivns74 at 2017-04-18 00:04:35

25. ffce15
View Tutorial          By: quad67 at 2017-04-18 12:44:03

26. Irhi47u
View Tutorial          By: Iikdbhs at 2017-04-19 02:42:30

27. octmlx
View Tutorial          By: mqmsin at 2017-04-20 00:29:04

28. Ixoxpcem
View Tutorial          By: Ivmwrbno at 2017-04-20 18:38:01

29. gnmijp
View Tutorial          By: rat46o at 2017-04-21 06:24:54