Application Hosting13 min read•Updated November 2026

How to Deploy a Spring Boot Application on a Linux VPS

Quick answer

Install a Java runtime that matches your build (for example openjdk-21-jre-headless), build the executable JAR with ./mvnw package or ./gradlew bootJar, and run it under systemd as a dedicated user with an explicit heap size (-Xmx) and server.address=127.0.0.1. Put Nginx in front for HTTPS, set server.forward-headers-strategy=framework so Spring sees the original scheme and client IP, and use Actuator's health endpoint for checks.

Spring Boot packages your application and an embedded web server (Tomcat by default) into one executable JAR, so deployment is mostly about running Java reliably: the right runtime version, a heap that fits the server, a supervisor that restarts the process, and a reverse proxy for TLS. This guide covers each step on Ubuntu 24.04 or Debian 12.

Step 1: Install the Java Runtime

Use the same major Java version your project is compiled for (check java.version in pom.xml or the toolchain in build.gradle). Spring Boot 3.x requires Java 17 or later. On Ubuntu 24.04:

sudo apt update
sudo apt install -y openjdk-21-jre-headless
java -version

The -headless package omits desktop libraries you do not need on a server. Eclipse Temurin builds from Adoptium are a common alternative if you need a specific vendor or update cadence.

Step 2: Build the Executable JAR

Build in CI or on your workstation:

# Maven
./mvnw -DskipTests package
# Gradle
./gradlew bootJar

The result is in target/ or build/libs/. Use the file without the -plain suffix: that one is the fat JAR containing all dependencies.

Step 3: Production Configuration

Keep environment-specific settings out of the JAR. Spring Boot reads environment variables automatically, mapping SPRING_DATASOURCE_URL to spring.datasource.url, and also reads an external application.properties placed next to the JAR or in a config/ subdirectory. A production profile might set:

# /opt/app/config/application-prod.properties
server.address=127.0.0.1
server.port=8080
server.forward-headers-strategy=framework
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=20s
management.endpoints.web.exposure.include=health,info
management.endpoint.health.probes.enabled=true
  • server.address=127.0.0.1 keeps the embedded server private; only Nginx reaches it.
  • server.forward-headers-strategy=framework makes Spring honour X-Forwarded-* headers, so redirects use https and logs show the real client IP. Only enable it when a trusted proxy always sets those headers.
  • server.shutdown=graceful lets in-flight requests finish when the service stops.
  • Expose only the Actuator endpoints you need. /actuator/health is safe; env, heapdump and similar must never be public.

Secrets such as database passwords go in an environment file read by systemd:

sudo adduser --system --group --home /opt/app app
sudo tee /opt/app/.env >/dev/null <<'EOF'
SPRING_PROFILES_ACTIVE=prod
SPRING_DATASOURCE_URL=jdbc:postgresql://127.0.0.1:5432/app
SPRING_DATASOURCE_USERNAME=app
SPRING_DATASOURCE_PASSWORD=use-a-long-random-password
EOF
sudo chown app:app /opt/app/.env && sudo chmod 600 /opt/app/.env

Step 4: Size the JVM Memory

The JVM uses more than the heap: metaspace for classes, a stack for every thread, code cache, direct buffers and garbage-collector overhead. A rough budget for a typical web service is heap + 300–500 MB. Set the heap explicitly so the JVM never grows into memory the database needs:

Server RAMAlso runningSuggested -Xmx
8 GBPostgreSQL + OS2–3 GB
16 GBPostgreSQL + Redis4–6 GB
32 GBSeveral servicesPer service, sum well below RAM

Alternatively, use -XX:MaxRAMPercentage=50 to size the heap as a share of available memory. Check real usage with ps -o rss,cmd -C java after the application has warmed up, and add a small swap file as a safety net (see our swap guide).

Step 5: Run It with systemd

sudo install -o app -g app -m 0644 -D app.jar /opt/app/app.jar
sudo tee /etc/systemd/system/app.service >/dev/null <<'EOF'
[Unit]
Description=Spring Boot application
After=network-online.target postgresql.service
Wants=network-online.target

[Service]
User=app
Group=app
WorkingDirectory=/opt/app
EnvironmentFile=/opt/app/.env
ExecStart=/usr/bin/java -Xms512m -Xmx2g -XX:+ExitOnOutOfMemoryError -jar /opt/app/app.jar
SuccessExitStatus=143
Restart=on-failure
RestartSec=5
TimeoutStopSec=40

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now app
journalctl -u app -f
  • SuccessExitStatus=143 treats the JVM's normal response to SIGTERM (exit code 143) as a clean stop, so systemd does not log a failure on every restart.
  • -XX:+ExitOnOutOfMemoryError makes the JVM exit on an out-of-memory error so systemd restarts it, instead of leaving a half-working process.
  • TimeoutStopSec should exceed the graceful shutdown timeout.

Spring Boot starts slower than Go or Node.js; allow 10–60 seconds depending on the application before health checks fail it.

Step 6: Nginx and HTTPS

server {
    listen 80;
    server_name app.example.com;
    client_max_body_size 20m;
    location / {
        proxy_pass http://127.0.0.1:8080;
        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 $scheme;
        proxy_set_header X-Forwarded-Port $server_port;
    }
    location /actuator/ {
        allow 127.0.0.1;
        deny all;
        proxy_pass http://127.0.0.1:8080;
    }
}
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d app.example.com

The second location blocks public access to Actuator; your monitoring can query it from the server itself. Our Let's Encrypt guide covers certificates in detail.

Step 7: Deploying New Versions

scp target/app-1.5.0.jar deploy@server:/tmp/
ssh deploy@server 'sudo install -D -o app -g app -m 0644 /tmp/app-1.5.0.jar /opt/app/releases/app-1.5.0.jar \
  && sudo ln -sfn /opt/app/releases/app-1.5.0.jar /opt/app/app.jar \
  && sudo systemctl restart app'
curl -fsS http://127.0.0.1:8080/actuator/health

Keep previous JARs in releases/ so rolling back is a symlink change and a restart. Database migrations (Flyway or Liquibase) run on startup; write them to be backward compatible so a rollback does not break on a newer schema.

Alternative: Container Image

Spring Boot can build an OCI image directly with ./mvnw spring-boot:build-image or ./gradlew bootBuildImage. If you deploy with Docker, publish the port only on 127.0.0.1 and keep Nginx in front; see our Docker deployment guide.

SkyRainCloud Plans for This Workload

Java services need more memory than most stacks: the JVM heap, metaspace and thread stacks all add up. A single Spring Boot service with PostgreSQL is comfortable on 8 GB; several services or large heaps call for the 16 GB and 32 GB tiers.

Intel Xeon Platinum 8269CY VPS

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — Intel28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthBusiness websites, small apps, scheduled jobs and botsOrder
VPS 2 — Intel416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
VPS 3 — Intel832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
VPS 4 — Intel1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,299/monthHigh-memory workloads and consolidated production serversCheck stock

AMD EPYC 7C13 VPS

Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — AMD28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthWebsites, small APIs, bots, staging and VPN serversOrder
VPS 2 — AMD416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,299/monthWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
VPS 3 — AMD832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,499/monthProduction databases, high-traffic sites, multi-container appsOrder
VPS 4 — AMD1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,899/monthLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.

Troubleshooting

SymptomCause and fix
UnsupportedClassVersionErrorThe runtime is older than the Java version used to compile; install the matching JRE
Process killed, OOM in dmesgHeap plus non-heap exceeds RAM; lower -Xmx or move to a larger plan
Redirects go to http://Set server.forward-headers-strategy=framework and pass X-Forwarded-Proto
502 right after restartThe app is still starting; check journalctl -u app and wait for "Started ... in N seconds"
Port 8080 already in useAnother instance or service is running: sudo ss -tlnp | grep 8080

Frequently Asked Questions

Which Java version do I need for Spring Boot?
Spring Boot 3.x requires Java 17 or newer. Install the same major version your project is compiled for; Java 21 is a common long-term-support choice.
Should I run the JAR directly or use Tomcat separately?
Run the executable JAR with its embedded server. Deploying a WAR to a standalone Tomcat is still possible but adds an extra component to maintain.
How much RAM does a Spring Boot app need?
Plan for the heap plus roughly 300–500 MB of non-heap memory. Many small services run with a 512 MB–2 GB heap; measure actual usage after warm-up.
How do I set the JVM heap size?
Pass -Xms and -Xmx in the systemd ExecStart line, or use -XX:MaxRAMPercentage to size it relative to available memory.
Why does systemd report my Spring Boot service as failed when I stop it?
The JVM exits with code 143 on SIGTERM. Add SuccessExitStatus=143 to the unit so systemd treats it as a normal stop.
How do I make Spring Boot work behind Nginx with HTTPS?
Bind it to 127.0.0.1, have Nginx pass X-Forwarded-Proto and related headers, and set server.forward-headers-strategy=framework.
Is it safe to expose Spring Boot Actuator?
Expose only health and info, and restrict the /actuator/ path to localhost or an internal network. Endpoints like env and heapdump can leak secrets.
How do I deploy a new version without long downtime?
Use graceful shutdown and a symlinked release. For zero downtime, run two instances on different ports behind an Nginx upstream and restart them one at a time.
Where are Spring Boot logs on the server?
When run under systemd and logging to the console, in the journal: journalctl -u app. Configure file logging with rotation only if you need log files.
Which SkyRainCloud plan suits Java applications?
One Spring Boot service with PostgreSQL fits the 8 GB plans. Choose 16 GB for several services or larger heaps, and 32 GB or more when running many JVMs on one server.
Instant UPI • ₹649/mo
Fast KVM Cloud Provisioning