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
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.
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.
tomcat_ajp.conf
<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/
</Location>
</VirtualHost>
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
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.
server.xml
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
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.
server.xml
<Connecter protocol="AJP/1.3"
address="::1"
port="8009"
secretRequired="false"
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.
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