Notice
This article is old, and some of the information may be outdated or no longer valid.
If you have any questions or need to confirm any details, we recommend contacting our support team for up-to-date information and personalized assistance.
Spring Boot is a free, open-source Java-based framework developed by Pivotal Team that is used to create a microservice. A microservice allows you to develop and deploy services independently.
Spring Boot provides a good platform for easily developing a standalone, production-ready application. It has been specifically designed to avoid complex XML configurations, reduce development time, and provide an easy way to get started with the application. You do not need to configure anything; everything is configured automatically.
In this tutorial, we explain how to deploy Spring Boot with Nginx as a reverse proxy on Ubuntu 24.04.
Requirements
- A cloud server running Ubuntu 24.04.
- A root password on your cloud server.
- Java version 8 or higher
Getting Started
Before you begin, make sure your server is up to date. If it is not, you can update your server with the following command:
# apt update && apt upgrade -yNext, we will install the zip package, as we will need it later:
# apt install zip -ySpring Boot is a Java-based application, so you will need to install Java on your server. You can install Java 21 with the following command:
# apt install openjdk-17-jdk -yOnce installed, you can check the Java version with the following command:
# java -versionYou should see the following output:
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)
Install the Spring Boot CLI Tool
Next, you will need to install Spring Boot CLI and other tools such as Gradle on your cloud server. You can easily create a new project with the Spring Boot CLI tool.
First, you will need to install SDKMAN on your cloud VPS server. You can do this with the following script:
# curl -s https://get.sdkman.io | bashOnce the installation is complete, you should see the following output:
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!!!
Next, activate SDKMAN with the following command:
# source "/root/.sdkman/bin/sdkman-init.sh"You can check all the options available with sdk using the following command:
# sdk helpYou should see the following output:
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
Next, you can install Spring Boot using the command shown below:
# sdk install springbootOnce installed, you should get the following output:
Downloading: springboot 4.0.6
In progress...
###################################################################################################################################### 100.0%
Installing: springboot 4.0.6
Done installing!
Setting springboot 4.0.6 as default.
You can also check the Spring Boot version with the following command:
# spring versionYou should see the following output:
Spring CLI v4.0.6
Next, install gradle by running the following command:
# sdk install gradle 9.4.1Create a Jar File with Gradle
Next, create a new project named hello-world with Spring Boot CLI and Gradle by running the following command:
# spring init --type=gradle-project --dependencies=web --name=hello hello-world
This command will create a new project directory named hello-world in your home directory, as shown below:
Using service at https://start.spring.io
Project extracted to '/root/hello-world'You can list all the parameters available with Spring Boot CLI by running the following command:
# spring init --listAmong many other options, you can specify options for building the project and various parameters:
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 |
+-------------------------+------------------------------------------+------------------+
Next, change to the hello-world directory and open your hello-word Java file:
# cd hello-world
# nano src/main/java/com/example/helloworld/HelloApplication.javaMake the following changes:
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";
}
}
Save and close the file. Then, build the application with the following command:
# ./gradlew buildYou should see the following output:
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
Then, run the application with the following command:
# java -jar build/libs/hello-world-0.0.1-SNAPSHOT.jarYour application is now running in a Tomcat servlet on port 8080, as shown below:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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)
Then, press CTRL+C to stop the application and run it again with Gradle:
# gradle bootRunYou should see the following output:
> 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)
Create a Systemd Service File for Spring Boot
Next, you will need to create a systemd service file to manage your application. You can do this with the following command:
# nano /etc/systemd/system/helloworld.serviceAdd the following lines:
[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
Save and close the file. Then, reload the systemd daemon with the following command:
# systemctl daemon-reloadNext, start the helloworld service and enable it to start at boot using the following command:
# systemctl start helloworld
# systemctl enable helloworldYou can now check the status of your service with the following command:
# systemctl status helloworldYou should see the following output:
● 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>
Configure Nginx as a Reverse Proxy
Next, you will need to configure Nginx as a reverse proxy to proxy requests from port 80 to 8080. First, install the Nginx server by running the following command:
# apt install nginx -yOnce installed, create a new virtual host configuration file for your application with the following command:
# nano /etc/nginx/conf.d/helloworld.confAdd the following lines:
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;
}
}Remember to replace the domain name example.com with your domain.
Save and close the file. Then, restart the Nginx service to apply the configuration changes with the following command:
# systemctl restart nginxTest Your Application
The Spring Boot application is now installed and configured with Nginx. You can access it by visiting the URL http://ejemplo.com in your browser. You should see your application on the following page:
Conclusion
Congratulations! You have successfully installed the Spring Boot application on your server with Nginx as a reverse proxy. For more information, you can consult the documentation for Spring Boot.