Tomcat – Apache / Tomcat port information

apache-2.2porttomcat

I have few questions regarding the Apache HTTPD server and the Tomcat web server port configurations.

Through netstat and TOMCAT/conf/server.xml I understand that:

  • 80 and 443 ports are used by Apache for HTTP and HTTPS requests respectively.
  • 8080 and 8443 ports are used by Tomcat for HTTP and HTTPS requests respectively.
  • There is one more Connector port="8009" using the "AJP/1.3" protocol. (AJP connector is used for cases where you wish to invisibly integrate Tomcat 4 into an existing (or new) Apache installation)

However:

  1. How is the 8009 port interrelated with the Apache and Tomcat ports? Does this mean how the requests are interchanged between the connector, Apache, Tomcat, etc.?

  2. What is starting this AJP connector (Tomcat or Apache)?

    Because even when Apache is started; I am NOT seeing a socket listening at 8009. But this is the port mentioned at apache2/conf/workers.properties.

    I think after Tomcat is started this port is available.

  3. In server.xml what is the purpose of redirectPort 8443?

<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Best Answer

Ok, I'll try answering you.

Consider Apache HTTPD and Apache Tomcat two friends (I'll call them in short HTTPD and Tomcat). Each of them has means of comunicating with other people, let's say by mobile phone and lineland phone or IM.

Tomcat has three phones for recieving calls:

  • One for recieving international calls in which he speaks the langauage spoken by most people in the (informatic) world, HTTP. This phone has an international agreed subnumber (port) which is 80, but can be any number. It happens that Tomcat being a bit eccentric preferes 8080 by default, so you can speak him HTTP at port 8080 by default.

  • Another phone for recieving calls from international VIP people, which want to be ultra sure they are speaking with Tomcat and nobody can listen their call, so they speak the previous international language but switching words (encryption, HTTPS). By international agreements this port is 443, but as we said Tomcat is eccentric, he chooses for this port 8443.

  • The third Tomcat's phone he uses it to recieve calls only from people that speak his own language, AJP (He lives in Java Application Server Country). By International Common Law, it's port 8009.

HTTPD has only two phones for recieving calls

  • The first two are the same as for Tomcat but HTTPD is not that eccentric prefering to use the normal agreed numbers, 80 for HTTP and 443 for HTTPS.

The story

Now HTTPD has a shop. Sometimes costumers ask for stuff not present in the shop but when he knows Tomcat has it he calls Tomcat and asks him to bring the things.For speaking with Tomcat HTTPD can use international languages, HTTP and HTTPS, but often Tomcat is more happy to speak his own language, AJP. So HTTPD knows that there are two translators that can help him speak AJP with Tomcat, mod_jk (http://tomcat.apache.org/connectors-doc/) and mod_proxy_ajp (https://httpd.apache.org/docs/2.4/mod/mod_proxy_ajp.html).

Now being more serious, by default, HTTPD listens on ports 80 for HTTP and port 443 for HTTPS.

Tomcat listens on port 8080 for HTTP, port 8443 for https and port 8009 for AJP.

You can configure the ports for HTTPS using Listen directives in it's configuration file, httpd.conf or files included from it. So grep for Listen to check them.

You can configure Tomcat for the ports in server.xml. In Tomcat language those are connectors (as opposed to Listen in HTTPD). And as for your configuration, if you setup Tomcat to use HTTPS he will redirect requests in HTTP to the port configured.

Keep in mind, HTTPD keeps care of his ports, Tomcat of his own ports and a port can be in listen only from a single application at a time. So if you have both HTTPD and Tomcat in the same machine, they fit nicely, as the ports used are different by default:

HTTPD: Ports 80 and 443

Tomcat: Ports 8080 8443 and 8009.