[JAVA] [Raspberry Pi] Try to link Apache2 and Tomcat


Link Tomcat with Apache2 of Raspberry Pi so that it can be published and accessed externally.


This article is based on the assumption that the initial settings of Raspberry Pi, domain acquisition, Apache2 installation, port opening, etc. have been completed. If you have not done so, we recommend that you make those settings first.

-Easy home server with raspberry pi web server version --Qiita -Made the Raspberry Pi web server compatible with https-Qiita

usage environment


First, update the package.

$ sudo apt update
$ sudp apt upgrade

After updating the package, install Tomcat. At the time of writing (2021/01/15), tomcat9 seems to be the latest.

$ sudo apt install tomcat9

After the installation is complete, check if it is working properly.

$ curl localhost:8080

The information on Apache Tomcat is rather successful. tomcat9 is designed to start automatically at startup when installed.

various settings

Apache2 settings

In this article, we will use the AJP protocol to integrate Apache and Tomcat. There is a similar method using mod_jk, but I don't want to install extra packages, so I won't explain it here. Apache + mod_jk + Various application server settings

First, enable the module for using AJP.

$ sudo a2enmod proxy proxy_ajp

Check the / etc/apache2/mods-enabled directory to see if the module is enabled. If there are three in the / etc/apache2/mods-enabled directory, proxy.conf, proxy.load, and proxy_ajp.load, it is successful.

Next, set the reverse proxy. Create tomcat_ajp.conf for configuration in the/etc/apache2/sites-available directory with root privileges.


<VirtualHost *:80>
        #Server name
        ServerName example.com
        #Server administrator email address
        ServerAdmin [email protected]

        #Reverse proxy settings
        <Location />
                ProxyPass ajp://localhost:8009/
                ProxyPassReverse ajp://localhost:8009/

After creating the configuration file, enable the settings.

$ sudo a2ensite tomcat_ajp

If you publish other sites in the same domain, it's a good idea to set the application name for the location or use a different domain / subdomain to separate the settings. Here, it is assumed that no other configuration file has been loaded for testing purposes.

Restart Apache for the settings to take effect.

$ sudo service apache2 restart

Tomcat 9 settings

There are two directories where the Tomcat configuration file is located, / etc/tomcat9 / and / var/lib/tomcat9/conf /, but the one that is included in / etc/tomcat9 / has priority. It looks like, so edit that. If that doesn't work, try changing the / var/lib/tomcat9/conf /.

Edit /etc/tomcat9/server.xml. First, comment out the default 8080 port part so that you can't access Tomcat directly.


    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               redirectPort="8443" />

Next, edit the part of port 8009. If there is a comment out, please remove it. Add the secretRequired option to prevent the AJP connector from connecting to untrusted sites.


    <Connecter protocol="AJP/1.3"
               redirectPort="8443" />

Restart Tomcat for the settings to take effect.

$ sudo service tomcat9 restart

Make sure port 8080 is closed.

$ curl localhost:8080

If the connection is refused, it is successful.

Operation check

First, access the server name set in the browser on Raspberry Pi. If you see the Tomcat root page, you are successful.

Check if it can be displayed in the browser of another terminal. If access does not work, please review the port opening, firewall settings, etc.

Thank you for your hard work.


-Install Tomcat on RaspberryPi-Qiita -Link Apache and Tomcat --Qiita --Ubuntu 19.10 Install Apache Tomcat 9 on Eoan Ermine Hello World --Qiita -How to make Apache httpd work with Tomcat -Apache + Tomcat installation and linkage settings

Recommended Posts

[Raspberry Pi] Try to link Apache2 and Tomcat
Apache and tomcat
Try to link Ruby and Java with Dapr
Procedure to link httpd and Tomcat9 with CentOS8.3 (multiple ProxyPass)
Try putting CentOS 8 on Raspberry Pi 3
Raspberry Pi Kubernetes and Docker downgraded story
Link Apache and Tomcat in a blink of an eye on CentOS 8
Now, put "InfluxDB + Telegraf + Chronograf" in CentOS8 and try to control the temperature of multiple Raspberry pi4.
Serially connect to Ubuntu on Raspberry Pi
Install Docker on Raspberry Pi 4 and Raspberry Pi OS 64bit
I tried to link grafana and postgres [docker-compose]
Introduced GROWI to Raspberry Pi 4 Model B (Ubuntu)
I tried to link JavaFX and Spring Framework.
Introduction to Apache Beam (1) ~ Reading and writing text ~
Just plug in the storage and power to run the Raspberry Pi (Ubuntu Server Edition)
Create a Java Servlet and JSP WAR file to deploy to Apache Tomcat 9 in Gradle
Spring Boot application built-in Tomcat, Apache and WebSocket integration
How to download a file (Servlet, HTML, Apache, Tomcat)
How to download the old version of Apache Tomcat
Try to implement tagging function using rails and js
Try scanning, analyzing, and transmitting the remote control of Mitsubishi's air conditioner with Raspberry Pi