Aviso
Este artículo es antiguo y es posible que parte de la información esté desactualizada o ya no sea válida en la actualidad.
Si tienes cualquier duda o necesitas confirmar algún detalle, te recomendamos contactar con nuestro equipo de soporte para recibir información actualizada y asistencia personalizada.
Spring Boot es un framework gratuito y de código abierto basado en Java desarrollado por Pivotal Team que se utiliza para crear un micro servicio. Un micro servicio permite desarrollar e implementar servicios de forma independiente.
Spring Boot proporciona una buena plataforma para desarrollar fácilmente una aplicación independiente y de entorno de producción. Ha sido especialmente diseñado para evitar configuraciones XML complejas, reducir el tiempo de desarrollo y ofrecer una manera fácil de comenzar con la aplicación. No necesita configurar nada, todo se configura automáticamente.
En este tutorial, te explicamos cómo implementar Spring Boot con Nginx como proxy inverso en Ubuntu 24.04.
Requisitos
- Un servidor en la nube corriendo con Ubuntu 24.04.
- Una contraseña root en tu servidor cloud.
- Java en su versión 8 o superior
Empezamos
Antes de empezar, asegúrate de que tu servidor está actualizado. Si no es así, puedes actualizar tu servidor con el siguiente comando:
# apt update && apt upgrade -yA continuación instalaremos el paquete zip ya que lo necesitaremos más tarde:
# apt install zip -ySpring Boot es una aplicación basada en Java, por lo que necesitarás instalar Java en tu servidor. Puedes instalar Java 21 con el siguiente comando:
# apt install openjdk-17-jdk -yUna vez instalado, puedes comprobar la versión de Java con el siguiente comando:
# java -versionDeberías ver el siguiente resultado:
openjdk 17.0.18 2026-01-20
OpenJDK Runtime Environment (build 17.0.18+8-Ubuntu-124.04.1)
OpenJDK 64-Bit Server VM (build 17.0.18+8-Ubuntu-124.04.1, mixed mode, sharing)
Instala la Herramienta Spring Boot CLI
A continuación, necesitarás instalar Spring Boot CLI y otras herramientas como Gradle en tu servidor cloud. Puedes crear un nuevo proyecto de forma fácil con la herramienta Spring Boot CLI.
En primer lugar, necesitarás instalar SDKMAN en tu servidor vps cloud. Puedes hacerlo con el siguiente script:
# curl -s https://get.sdkman.io | bashUna vez que la instalación ha sido completada, deberías ver el siguiente resultado:
All done!
You are subscribed to the STABLE channel.
Please open a new terminal, or run the following in the existing one:
source "/root/.sdkman/bin/sdkman-init.sh"
Then issue the following command:
sdk help
Enjoy!!!
A continuación, activa SDKMAN con el siguiente comando:
# source "/root/.sdkman/bin/sdkman-init.sh"Puedes comprobar todas las opciones disponibles con sdk utilizando el siguiente comando:
# sdk helpDeberías ver el siguiente resultado:
NAME
sdk - The command line interface (CLI) for SDKMAN!
SYNOPSIS
sdk <subcommand> [candidate] [version]
DESCRIPTION
SDKMAN! is a tool for managing parallel versions of multiple JVM related
Software Development Kits on most Unix based systems. It provides a
convenient Command Line Interface (CLI) and API for installing, switching,
removing and listing Candidates.
SUBCOMMANDS & QUALIFIERS
help [subcommand]
install <candidate> [version] [path]
uninstall <candidate> <version>
list [candidate]
use <candidate> <version>
config no qualifier
default <candidate> [version]
home <candidate> <version>
env [init|install|clear]
current [candidate]
upgrade [candidate]
version no qualifier
selfupdate [force]
update no qualifier
flush [tmp|metadata|version]
EXAMPLES
sdk install java 17.0.0-tem
sdk help install
A continuación, puedes instalar Spring Boot utilizando el comando que se muestra más abajo:
# sdk install springbootUna vez instalado, deberías obtener el siguiente resultado:
Downloading: springboot 4.0.6
In progress...
###################################################################################################################################### 100.0%
Installing: springboot 4.0.6
Done installing!
Setting springboot 4.0.6 as default.
También puedes comprobar la versión de Spring Boot con el siguiente comando:
# spring versionDeberías ver el siguiente resultado:
Spring CLI v4.0.6
A continuación, instala gradle ejecutando el siguiente comando:
# sdk install gradle 9.4.1Crea un archivo Jar con Gradle
A continuación, crea un nuevo proyecto denominado hello-world con Spring Boot CLI y Gradle ejecutando el siguiente comando:
# spring init --type=gradle-project --dependencies=web --name=hello hello-world
Este comando creará un directorio de nuevo proyecto llamado hello-world en tu directorio principal como se muestra más abajo:
Using service at https://start.spring.io
Project extracted to '/root/hello-world'Puedes hacer una lista de todos los parámetros disponibles con Spring Boot CLI ejecutando el siguiente comando:
# spring init --listEntre otras muchas opciones, puedes especificar opciones para compilar el proyecto y diferentes parámetros:
Project types (* denotes the default)
+-----------------------+--------------------------------------------------------------+--------------------------------------------+
| Id | Description | Tags |
+-----------------------+--------------------------------------------------------------+--------------------------------------------+
| gradle-build | Generate a Gradle build file. | build:gradle,format:build |
| | | |
| gradle-project * | Generate a Gradle based project archive using the Groovy | build:gradle,dialect:groovy,format:project |
| | DSL. | |
| | | |
| gradle-project-kotlin | Generate a Gradle based project archive using the Kotlin | build:gradle,dialect:kotlin,format:project |
| | DSL. | |
| | | |
| maven-build | Generate a Maven pom.xml. | build:maven,format:build |
| | | |
| maven-project | Generate a Maven based project archive. | build:maven,format:project |
+-----------------------+--------------------------------------------------------------+--------------------------------------------+
Parameters
+-------------------------+------------------------------------------+------------------+
| Id | Description | Default value |
+-------------------------+------------------------------------------+------------------+
| artifactId | project coordinates (infer archive name) | demo |
| bootVersion | spring boot version | 4.0.6 |
| configurationFileFormat | configuration file format | properties |
| description | project description | |
| groupId | project coordinates | com.example |
| javaVersion | language level | 17 |
| language | programming language | java |
| name | project name (infer application name) | |
| packageName | root package | com.example.demo |
| packaging | project packaging | jar |
| type | project type | gradle-project |
| version | project version | 0.0.1-SNAPSHOT |
+-------------------------+------------------------------------------+------------------+
A continuación, cambia el directorio a hello-world y abre tu archivo hello-word de Java:
# cd hello-world
# nano src/main/java/com/example/helloworld/HelloApplication.javaHaz los siguientes cambios:
package com.example.helloworld;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
@RestController
class Hello {
@RequestMapping("/")
String index() {
return "Hello world";
}
}
Guarda y cierra el archivo. Después, crea la aplicación con el siguiente comando:
# ./gradlew buildDeberías ver el siguiente resultado:
Downloading https://services.gradle.org/distributions/gradle-9.4.1-bin.zip
.............10%.............20%.............30%.............40%.............50%.............60%..............70%.............80%.............90%.............100%
Welcome to Gradle 9.4.1!
Here are the highlights of this release:
- Java 26 support
- Non-class-based JVM tests
- Enhanced console progress bar
For more details see https://docs.gradle.org/9.4.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
BUILD SUCCESSFUL in 53s
7 actionable tasks: 7 executed
Después, ejecuta la aplicación con el siguiente comando:
# java -jar build/libs/hello-world-0.0.1-SNAPSHOT.jarAhora tu aplicación está corriendo en un servlet Tomcat en el puerto 8080, como se muestra más abajo:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v4.0.6)
2026-04-27T13:46:22.426+02:00 INFO 4439 --- [hello] [ main] c.example.hello_world.HelloApplication : Starting HelloApplication v 0.0.1-SNAPSHOT using Java 17.0.18 with PID 4439 (/root/hello-world/build/libs/hello-world-0.0.1-SNAPSHOT.jar started by root in /root/hello-w orld)
2026-04-27T13:46:22.437+02:00 INFO 4439 --- [hello] [ main] c.example.hello_world.HelloApplication : No active profile set, fall ing back to 1 default profile: "default"
2026-04-27T13:46:24.315+02:00 INFO 4439 --- [hello] [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with por t 8080 (http)
2026-04-27T13:46:24.353+02:00 INFO 4439 --- [hello] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2026-04-27T13:46:24.353+02:00 INFO 4439 --- [hello] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [A pache Tomcat/11.0.21]
2026-04-27T13:46:24.614+02:00 INFO 4439 --- [hello] [ main] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 2046 ms
2026-04-27T13:46:25.838+02:00 INFO 4439 --- [hello] [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2026-04-27T13:46:25.871+02:00 INFO 4439 --- [hello] [ main] c.example.hello_world.HelloApplication : Started HelloApplication in 4.594 seconds (process running for 5.906)
Después, presiona CTRL+C para parar la aplicación y ejecutarla de nuevo con Gradle:
# gradle bootRunDeberías ver el siguiente resultado:
> Task :bootRun
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v4.0.6)
2026-04-27T13:47:54.415+02:00 INFO 4523 --- [hello] [ main] c.example.hello_world.HelloApplication : Starting HelloApplication using Java 17.0.18 with PID 4523 (/root/hello-world/build/classes/java/main started by root in /root/hello-world)
2026-04-27T13:47:54.419+02:00 INFO 4523 --- [hello] [ main] c.example.hello_world.HelloApplication : No active profile set, falling back to 1 default profile: "default"
2026-04-27T13:47:55.269+02:00 INFO 4523 --- [hello] [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2026-04-27T13:47:55.281+02:00 INFO 4523 --- [hello] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2026-04-27T13:47:55.282+02:00 INFO 4523 --- [hello] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.21]
2026-04-27T13:47:55.426+02:00 INFO 4523 --- [hello] [ main] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 962 ms
2026-04-27T13:47:55.911+02:00 INFO 4523 --- [hello] [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2026-04-27T13:47:55.925+02:00 INFO 4523 --- [hello] [ main] c.example.hello_world.HelloApplication : Started HelloApplication in 1.986 seconds (process running for 2.511)
Crea un Archivo de Servicio Systemd para Spring Boot
A continuación, necesitarás crear un archivo de servicio systemd para gestionar tu aplicación. Puedes hacerlo con el siguiente comando:
# nano /etc/systemd/system/helloworld.serviceAñade las siguientes líneas:
[Unit]
Description=Spring Boot HelloWorld
After=syslog.target network.target
[Service]
User=root
Type=simple
ExecStart=/usr/bin/java -jar /root/hello-world/build/libs/hello-world-0.0.1-SNAPSHOT.jar
Restart=always
StandardOutput=journal
StandardError=journal
SyslogIdentifier=helloworld
[Install]
WantedBy=multi-user.target
Guarda y cierra el archivo. Entonces, carga de nuevo el demonio systemd con el siguiente comando:
# systemctl daemon-reloadA continuación, inicia el servicio helloworld y permite que se inicie en boot utilizando el siguiente comando:
# systemctl start helloworld
# systemctl enable helloworldAhora ya puedes comprobar el estado de tu servicio con el siguiente comando:
# systemctl status helloworldDeberías ver el siguiente resultado:
● helloworld.service - Spring Boot HelloWorld
Loaded: loaded (/etc/systemd/system/helloworld.service; disabled; preset: enabled)
Active: active (running) since Mon 2026-04-27 13:52:48 CEST; 4s ago
Main PID: 4670 (java)
Tasks: 18 (limit: 2263)
Memory: 97.1M (peak: 97.4M)
CPU: 4.865s
CGroup: /system.slice/helloworld.service
└─4670 /usr/bin/java -jar /root/hello-world/build/libs/hello-world-0.0.1-SNAPSHOT.jar
Apr 27 13:52:50 amb-dev helloworld[4670]: \\/ ___)| |_)| | | | | || (_| | ) ) ) )
Apr 27 13:52:50 amb-dev helloworld[4670]: ' |____| .__|_| |_|_| |_\__, | / / / /
Apr 27 13:52:50 amb-dev helloworld[4670]: =========|_|==============|___/=/_/_/_/
Apr 27 13:52:50 amb-dev helloworld[4670]: :: Spring Boot :: (v4.0.6)
Apr 27 13:52:50 amb-dev helloworld[4670]: 2026-04-27T13:52:50.377+02:00 INFO 4670 --- [hello] [ main] c.example.hello_world.HelloApplication : St>
Apr 27 13:52:50 amb-dev helloworld[4670]: 2026-04-27T13:52:50.387+02:00 INFO 4670 --- [hello] [ main] c.example.hello_world.HelloApplication : No>
Apr 27 13:52:52 amb-dev helloworld[4670]: 2026-04-27T13:52:52.299+02:00 INFO 4670 --- [hello] [ main] o.s.boot.tomcat.TomcatWebServer : To>
Apr 27 13:52:52 amb-dev helloworld[4670]: 2026-04-27T13:52:52.330+02:00 INFO 4670 --- [hello] [ main] o.apache.catalina.core.StandardService : St>
Apr 27 13:52:52 amb-dev helloworld[4670]: 2026-04-27T13:52:52.331+02:00 INFO 4670 --- [hello] [ main] o.apache.catalina.core.StandardEngine : St>
Apr 27 13:52:52 amb-dev helloworld[4670]: 2026-04-27T13:52:52.563+02:00 INFO 4670 --- [hello] [ main] b.w.c.s.WebApplicationContextInitializer : Ro>
Configura Nginx como un Proxy reverso
A continuación, necesitarás configurar Nginx como proxy reverso para una petición de proxy en los puertos 80 a 8080. Primero, instala el servidor Nginx ejecutando el siguiente comando:
# apt install nginx -yUna vez instalado, crea un archivo nuevo de configuración virtual host para tu aplicación con el siguiente comando:
# nano /etc/nginx/conf.d/helloworld.confAñade las siguientes líneas:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}No olvides modificar el nombre del dominio esample.com por tu dominio.
Guarda y cierra el archivo. Después, reinicia el servicio Nginx para aplicar los cambios de configuración con el siguiente comando:
# systemctl restart nginxTestea Tu Aplicación
La aplicación Spring Boot ya está instalada y configurada con Nginx. Puedes acceder a ella visitando la URL http://ejemplo.com en tu navegador. Deberías ver tu aplicación en la siguiente página:
Conclusión
¡Felicidades! Has instalado con éxito la aplicación Spring Boot en tu servidor con Nginx como proxy reverso. Para más información, puedes consultar la documentación de Spring Boot.