Installing ODK Aggregate with Tomcat in the Apache HTTPD environment

Hai Everyone... Greetings from West Java Indonesia.

Share our experience using ODK-Aggregate with Tomcat settings in the Apache HTTPD environment as you can see at https://rsudcibabat.cimahikota.go.id/odk

The ODK ecosystem is our first choice, mainly because it is an open source in supporting us for collecting the surveillance data in the field related to infections, occupational safety and maintenance of hospital facilities.

Our server environment spec:

  • Centos 7
  • Apache HTTPD 2.4.6 (SSL :443)
  • PHP 7.3.12
  • MySQL 5.7
  • Tomcat 8 (port 8080)
  • ODK Aggregate 2.0.5 (.war)

STEP 1 - TOMCAT IS ON

Assumed you have successfully installed Tomcat on port 8080.

STEP 2 - SETTING UP THE workers.properties

Make sure you have workers.properties in httpd conf, in our case at Centos 7 environment located at /etc/httpd/conf/workers.properties:

workers.apache_log=/var/log/httpd
worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=yourdomain.com
worker.worker1.port=8009
worker.worker1.socket_timeout=10

STEP 3 - SETTING UP THE server.xml

Make sure set default connector port or uncomment in your_tomcat_dir/conf/server.xml:

<Server port="8005" shutdown="SHUTDOWN">...</Server>
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

STEP 4 - ACTIVATE THE proxy_ajp_module

Next thing todo is connecting Tomcat with Apache HTTPD is better using proxy through the proxy_ajp_module as we never succeeded with mod_jk module.

Make sure the module is available, check with:
# apachectl -M | grep ajp
proxy_ajp_module (shared)

STEP 5 - INSTALL ODK-AGGREGATE

Assumed you have successfully load ODK-Aggregate.war with Tomcat at directory /odk
http://localhost:8080/odk

STEP 6 - ADD PROXY TO APACHE CONF

At the /etc/httpd/conf.d/ directory, edit existing virtual host conf file or create a new one and name it for example tomcat_proxy.conf then fill within virtual host:

Assumed you have SSL connection at 443, otherwise change to *:80 and add the following proxy configuration at the end of virtual host:

<VirtualHost *:443>

# REVERSE PROXY CONFIGURATION
# ProxyRequests Off  prevent fraudulent use of proxy server
ProxyRequests Off

# ProxyPreserveHost makes Apache pass the original Host header to the backend server. This is useful, as it makes the backend server aware of the address used to access the application.
ProxyPreserveHost On
	
# ProxyPass specifies that everything under the root URL (/) should be mapped to the backend server at the given address.
ProxyPass /odk http://localhost:8080/odk
	
# ProxyPassReverse makes sure that if the backend server returns a location redirect header, the client’s browser will be redirected to the proxy address and not the backend server address, which would not work as intended.
ProxyPassReverse /odk http://localhost:8080/odk

</VirtualHost>

STEP 7 - RESTART THE APACHE HTTPD AND TOMCAT

sudo systemctl restart httpd
sudo systemctl restart tomcat

Assumed your domain name is yourdomain.com then open the url without need to append port :8080:
https://yourdomain.com/odk

That's all folks! Let me know if you have successfully installed it in other distros / win-server environment

Alternatively, you can follow the instructions in the following article:
How to set up Apache webserver proxy in front of Apache Tomcat on Red Hat Linux

1 Like