Make Gadgets Work

Tomcat 8.5.4 on Fedora behind Nginx

Ankit Mittal


Install Oracle Java

#install jdk
wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""
#install jre
wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""
#enable firefox plugin
alternatives --install /usr/lib/mozilla/plugins/ /usr/java/jdk1.8.0_102/jre/lib/i386/ 20000
URL for JDK and JRE is best obtained directly from oracle website -
#Download Tomcat ```language-bash line-numbers su mkdir /opt/tomcat/ && cd /opt/tomcat wget wget ```

Check MD5


Create a TOMCAT Group and User then grant access

groupadd tomcat
useradd -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
cd /opt/tomcat
chgrp -R tomcat conf
chmod g+rwx conf
chmod g+r conf/*
chown -R tomcat bin/ webapps/ work/ temp/ logs/

Create Service for Tomcat

nano /etc/systemd/system/tomcat.service

# Systemd unit file for tomcat
Description=Apache Tomcat Web Application Container





systemctl start tomcat.service
systemctl enable tomcat.service

Alternative start and stop

cd apache-tomcat-8.5.4/bin
chmod 700 /opt/tomcat/apache-tomcat-8.5.4/bin/*.sh
ln -s /opt/tomcat/apache-tomcat-8.5.4/bin/ /usr/bin/tomcatup
ln -s /opt/tomcat/apache-tomcat-8.5.4/bin/ /usr/bin/tomcatdown

Change port

nano /opt/tomcat/apache-tomcat-8.5.4/conf/server.xml

Around line 69 is the connector tag where the port=8080 is specified. For this example lets change it to 8081. After change the connector tag in server.xml will look as below:

    <Connector port="8081" protocol="HTTP/1.1"
               redirectPort="8443" />

Add tomcat Users

#open tomcat-users.xml and add new users before </tomcat-user> tag
nano /opt/tomcat/apache-tomcat-8.5.4/conf/tomcat-users.xml

sample user:

<role rolename="admin-gui"/>
<user username="admin" password="some admin password" roles="admin-gui"/>
<role rolename="manager-gui"/>
<user username="jhondoe" password="some password" roles="manager-gui"/>


touch /opt/tomcat/apache-tomcat-8.5.4/webapps/ROOT/testankit.jsp
nano /opt/tomcat/apache-tomcat-8.5.4/webapps/ROOT/testankit.jsp
#restart tomcat
systemctl restart tomcat.service

Open the browser and enter http://localhost:8080 (or whatever port you have configured Tomcat on.)

Configure Nginx Reverse Proxy for Tomcat

  • Configure the dynamic DNS. Steps will be as per my previous post. For purpose of this step I will be assuming you created a DDNS named
  • Update /etc/hosts to include
sudo nano /etc/hosts
#Make an entry in your hosts  localhost.localdomain localhost
  • Now create nginx conf file using sudo nano /etc/nginx/conf.d/tomcat.confas shown below
upstream tomcat {

server {
     listen      80;
     access_log  /var/log/nginx/tomcat.access.log;
     error_log   /var/log/nginx/tomcat.error.log;
     proxy_buffers 16 64k;
     proxy_buffer_size 128k;

        location / {
         proxy_pass  http://tomcat;
         proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
         proxy_redirect off;
         proxy_set_header    Host            $host;
         proxy_set_header    X-Real-IP       $remote_addr;
         proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header    X-Forwarded-Proto https;
  • Finally reload and restart services
sudo systemctl daemon-reload
sudo systemctl start nginx.service
sudo systemctl start tomcat.service