A logo showing the text blog.marcnuri.com
Español
Home»Java»Running Apache Tomcat and Apache HTTPD on port 80 simultaneously

Recent Posts

  • Fabric8 Kubernetes Client 7.2 is now available!
  • Connecting to an MCP Server from JavaScript using AI SDK
  • Connecting to an MCP Server from JavaScript using LangChain.js
  • The Future of Developer Tools: Adapting to Machine-Based Developers
  • Connecting to a Model Context Protocol (MCP) Server from Java using LangChain4j

Categories

  • Artificial Intelligence
  • Front-end
  • Go
  • Industry and business
  • Java
  • JavaScript
  • Legacy
  • Operations
  • Personal
  • Pet projects
  • Tools

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • August 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • September 2019
  • July 2019
  • March 2019
  • November 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • December 2017
  • July 2017
  • January 2017
  • December 2015
  • November 2015
  • December 2014
  • March 2014
  • February 2011
  • November 2008
  • June 2008
  • May 2008
  • April 2008
  • January 2008
  • November 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007

Running Apache Tomcat and Apache HTTPD on port 80 simultaneously

2015-11-15 in Java tagged Apache / Apache HTTP / Apache Tomcat / Application / Connector / HTTP / Java / Server / Tomcat / Web / www by Marc Nuri | Last updated: 2021-02-21
Versión en Español

Apache Tomcat and the World Wide Web

Apache Tomcat
Apache Tomcat

Usually when running an application server, such as Apache Tomcat, you bind a connector directly on port 80. This way users visiting your web application will be able to navigate through your server just by calling your domain instead of calling your domain and special port (http://yourdomain.com:8080). If there is no option to bind a Tomcat connector on port 80 (some systems ban this functionality for security purposes), there are other ways to achieve this behavior such as setting a redirect on port 80 to port 8080 (Tomcat's default, or any other) using IPTables any other port redirection tool. Both options are really simple procedures, but are a great issue if you need to run a simple HTTP server on your machine too.

Apache HTTP and mod_proxy

To solve this problem we can run Apache HTTPD as a front-end proxy for Apache Tomcat and redirect traffic to the application server based on a set of rules. In this tutorial we will use mod_proxy, although there are many other options available.

Apache Tomcat - Apache HTTPd - mod_proxy front-end
Apache Tomcat - Apache HTTPd - mod_proxy front-end

This tutorial assumes that Apache Tomcat is already installed and configured with the default connector settings (port 8080) and Apache HTTP is installed too with the default listener settings (port 80).

For this tutorial we are going to assume that there are 2 different domains (tomcatserver.com and httpserver.com) pointing to the same IP address. The user expects to reach the application server when navigating to one domain and the web server when navigating to the other.

First step is make sure that the file httpd.conf has mod_proxy enabled (which is by default), so in case it isn't, uncomment the following line.

LoadModule proxy_module modules/mod_proxy.so

Taking into account that there are 2 domains, we need to use the NameVirtualHost directive and define two virtual hosts based on the different domains.

NameVirtualHost *:80

Next, we define the virtual host that will redirect traffic to tomcat. In case tomcat has some virtual hosts defined too, we'll add a ServerAlias for each domain that needs to reach tomcat.

1<VirtualHost *:80>
2    ServerAdmin root@localhost
3    ServerName tomcatserver.com
4    ServerAlias tomcatserver1.com
5    ServerAlias tomcatserver2.com
6    DefaultType text/html
7    ProxyRequests off
8    ProxyPreserveHost On
9    ProxyPass / http://localhost:8080/
10    ProxyPassReverse / http://localhost:8080/
11</VirtualHost>

The DefaultType directive is used to set the default type for responses which don't specify it. This may happen with badly configured web applications and is something that Tomcat does by default and may arise bugs when using the proxified version.

ProxyRequests is a security measure, setting it to off will prevent your machine being used as a forward proxy server.

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.

Next, we define the virtual host that will serve pages directly from Apache HTTP.

1<VirtualHost *:80>    
2    ServerAdmin root@localhost
3    DocumentRoot /var/www/
4    ServerName httpserver.com
5    #Aliases
6    ServerAlias httpserver1.com
7    ...
8</VirtualHost>

Proxy Rules

In this example we've assumed there are two different domains (or more) and that each domain will point to a different type of server. mod_proxy allows us to define more advanced rules, to proxy content based on other rules such as the context path.

1<VirtualHost *:80>    
2    ServerAdmin root@localhost
3    DocumentRoot /var/www/
4    ServerName httpserver.com
5    #Aliases
6    ServerAlias httpserver1.com
7    ProxyPass /tomcat http://localhost:8080/
8    ...
9</VirtualHost>

With this code, all traffic will be served by Apache HTTP, and only those requests to the '/tomcat' context path will be proxied to Apache Tomcat. So http://httpserver.com/index.php will be served by a Apache HTTP and http://httpserver.com/tomcat/index.do will be served by Apache Tomcat.

Twitter iconFacebook iconLinkedIn iconPinterest iconEmail icon

Post navigation
Incremental E-Mail backup and migration using mnIMAPSyncjava.lang.OutOfMemoryError: GC overhead limit exceeded
© 2007 - 2025 Marc Nuri