Installazione · 12 min read · Dec 18, 2025

Come installare Apache Tomcat con Nginx Reverse Proxy su Ubuntu 22.04

Apache Tomcat è un server web Java open-source e un contenitore Servlet utilizzato per ospitare applicazioni web scritte in Java. È la prima scelta degli sviluppatori web per costruire e mantenere siti web e applicazioni dinamiche basate sulla piattaforma software Java. È un progetto open-source sviluppato dalla Apache Software Foundation. Tomcat consente a un server web di gestire contenuti web dinamici basati su Java.

Questo tutorial ti mostrerà come installare Apache Tomcat su Ubuntu 22.04.

Prerequisiti

  • Un server che esegue Ubuntu 22.04.
  • Un nome di dominio valido puntato all’IP del tuo server.
  • Una password di root configurata sul server.

Installa Java JDK

Apache Tomcat è un’applicazione basata su Java, quindi Java deve essere installato sul tuo server. Se Java non è installato, puoi installarlo utilizzando il seguente comando:

apt install default-jdk -y

Una volta installato Java, puoi verificare la versione di Java utilizzando il seguente comando:

java -version

Otterrai il seguente output:

openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1, mixed mode, sharing)

Installa Apache Tomcat su Ubuntu 22.04

Per prima cosa, è una buona idea eseguire Tomcat come utente separato. Puoi creare un utente Tomcat con il seguente comando:

useradd -m -d /opt/tomcat -U -s /bin/false tomcat

Successivamente, scarica l’ultima versione di Apache Tomcat con il seguente comando:

wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.20/bin/apache-tomcat-10.0.20.tar.gz

Una volta scaricato Apache Tomcat, estrai il file scaricato all’interno della directory /opt:

tar xzvf apache-tomcat-10*tar.gz -C /opt/tomcat --strip-components=1

Successivamente, imposta la proprietà e i permessi corretti per la directory di Tomcat:

chown -R tomcat:tomcat /opt/tomcat/   
chmod -R u+x /opt/tomcat/bin

Una volta terminato, puoi procedere al passaggio successivo.

Crea un utente amministrativo per Tomcat

Per impostazione predefinita, Tomcat può essere accessibile senza alcuna autenticazione. Quindi, è consigliato abilitare l’autenticazione e creare un utente amministrativo per Tomcat. Puoi aggiungerlo modificando il file di configurazione degli utenti di Tomcat:

nano /opt/tomcat/conf/tomcat-users.xml

Aggiungi le seguenti righe sopra la riga :


Salva e chiudi il file quando hai finito.

Abilita l’accesso remoto a Tomcat

Per impostazione predefinita, Tomcat è configurato per essere accessibile solo dall’host locale. Quindi, è consigliato abilitare l’accesso remoto a Tomcat per gestirlo da un host remoto.

Per abilitare l’app manager da un host remoto, modifica il seguente file:

nano /opt/tomcat/webapps/manager/META-INF/context.xml

Rimuovi la seguente riga:

  

Per abilitare l’app host manager da un host remoto, modifica il seguente file:

nano /opt/tomcat/webapps/host-manager/META-INF/context.xml

Rimuovi la seguente riga:

  

Salva e chiudi il file quando hai finito.

Crea un file di servizio per Apache Tomcat

Successivamente, dovrai creare un file di servizio per gestire il servizio Tomcat tramite systemd. Puoi crearlo utilizzando il seguente comando:

nano /etc/systemd/system/tomcat.service

Aggiungi le seguenti righe:

[Unit]
Description=Tomcat
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

Salva e chiudi il file, quindi ricarica il demone systemd per applicare le modifiche:

systemctl daemon-reload

Successivamente, avvia il servizio Tomcat e abilitalo per avviarsi al riavvio del sistema con il seguente comando:

systemctl start tomcat  
systemctl enable tomcat

Puoi controllare lo stato di Apache Tomcat utilizzando il seguente comando:

systemctl status tomcat

Otterrai il seguente output:

? tomcat.service - Tomcat
     Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-29 08:11:54 UTC; 6s ago
    Process: 18959 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
   Main PID: 18966 (java)
      Tasks: 29 (limit: 4630)
     Memory: 116.4M
        CPU: 5.312s
     CGroup: /system.slice/tomcat.service
             ??18966 /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Dja>

Apr 29 08:11:54 ubuntu systemd[1]: Starting Tomcat...
Apr 29 08:11:54 ubuntu startup.sh[18959]: Tomcat started.
Apr 29 08:11:54 ubuntu systemd[1]: Started Tomcat.

A questo punto, Tomcat è avviato e ascolta sulla porta 8080. Puoi controllarlo con il seguente comando:

ss -antpl | grep java

Otterrai il seguente output:

LISTEN 0      1      [::ffff:127.0.0.1]:8005             *:*    users:(("java",pid=18966,fd=53))                                                                                                                                                                                                                                                                                
LISTEN 0      100                     *:8080             *:*    users:(("java",pid=18966,fd=43))   

Una volta terminato, puoi procedere al passaggio successivo.

Configura Nginx come Reverse Proxy per Tomcat

Successivamente, dovrai creare un Nginx come reverse proxy per Apache Tomcat. Prima di tutto, installa il server web Nginx con il seguente comando:

apt-get install nginx -y

Una volta installato il server web Nginx, crea un file di configurazione del virtual host Nginx utilizzando il seguente comando:

nano /etc/nginx/conf.d/tomcat.conf

Aggiungi le seguenti righe:

server {
  listen 80;

  server_name    tomcat.example.com;
  access_log /var/log/nginx/tomcat-access.log;
  error_log /var/log/nginx/tomcat-error.log;

  location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8080/;
  }
}

Salva e chiudi il file, quindi verifica la sintassi di Nginx per eventuali errori utilizzando il seguente comando:

ginx -t

Otterrai il seguente output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Successivamente, riavvia il servizio Nginx per applicare le modifiche:

systemctl restart nginx

Puoi anche controllare lo stato di Nginx utilizzando il seguente comando:

systemctl status nginx

Dovresti vedere il seguente output:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-29 08:15:28 UTC; 8s ago
       Docs: man:nginx(8)
    Process: 19070 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 19071 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 19072 (nginx)
      Tasks: 3 (limit: 4630)
     Memory: 3.3M
        CPU: 63ms
     CGroup: /system.slice/nginx.service
             ??19072 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??19073 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "```

## Accedi ad Apache Tomcat

Ora, apri il tuo browser web e accedi all'interfaccia web di Apache Tomcat utilizzando l'URL http://tomcat.example.com. Dovresti vedere il dashboard di Tomcat nella seguente schermata:

![Apache Tomcat](/files/9ce1bf58-ecfc-440f-a900-f03ebb183fed.png)

Clicca su Manager App. Ti verrà chiesto di autenticarti come mostrato di seguito:

![Login Tomcat](/files/449662ad-1143-4e50-a946-6b6701f5662d.png)

Fornisci il tuo nome utente admin e la password, quindi clicca sul pulsante Accedi. Dovresti vedere il dashboard dell'app Manager nella seguente schermata:

![Dashboard Apache Tomcat](/files/c4ae527f-3ddf-4f15-896f-746728e7f6bb.png)

Per accedere all'app Host Manager, clicca su Host Manager. Dovresti vedere la seguente schermata:

![Tomcat Virtual Host Manager](/files/853ea55f-9f2b-4879-9eed-d8d5026e9838.png)

Clicca su Server Status. Dovresti vedere lo stato di Apache Tomcat nella seguente schermata:

![Stato Server Tomcat](/files/76b7c9df-9df7-4907-9db9-4d3cfdbaa064.png)

## Conclusione

Congratulazioni! Hai installato con successo Apache Tomcat con Nginx come reverse proxy su Ubuntu 22.04. Ora puoi creare e ospitare la tua prima applicazione Java utilizzando Apache Tomcat. Sentiti libero di chiedermi se hai domande.
Share: X/Twitter LinkedIn

Ricevi i nuovi post nella tua casella di posta.

Nessuno spam. Disiscriviti in qualsiasi momento.