Learn how to run a Spring Boot application on a Linux server using Java, systemd, Nginx reverse proxy, and SSL. Complete guide with latest commands and production-ready setup.
Introduction
Running a Spring Boot application on a Linux server is one of the most reliable ways to build scalable backend services. In this guide, we walk through a complete setup, starting from a fresh server to a production-ready deployment with process management, reverse proxy, and SSL.
Prerequisites
Before we begin, let’s ensure we have the following in place:
- A Ubuntu 24.04 dedicated server or KVM VPS.
- A basic programming knowledge.
- A domain name pointing A record to server IP.
Learn how to run a Spring Boot application on a Linux server using Java
We focus on clarity, stability, and real-world practices.
1. Prepare the Linux Server
We start with a clean and updated system.
sudo apt update && sudo apt upgrade -y
Install essential utilities:
sudo apt install -y curl wget unzip git
2. Install Java and Maven (Latest LTS)
Spring Boot requires Java. We recommend OpenJDK 17 or 21.
sudo apt install -y openjdk-21-jdk
Verify installation:
java -version
Set environment variable:
echo "JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))" | sudo tee -a /etc/environment
source /etc/environment
Install Maven
Execute following command to install Maven:
sudo apt install -y maven
Verify:
mvn -v
3. Upload or Clone Application
We place our application inside a structured directory.
sudo mkdir -p /var/www/springboot_app && cd /var/www/springboot_app
Clone repository:
git clone https://github.com/your-repo/springboot-app.git .
Or upload JAR directly:
scp app.jar root@server-ip:/var/www/springboot_app/
Note: For this demonstration purpose we are using test Spring boot application using Maven. If you will use app.jar file, you perform following steps. We have tested it using mvn spring-boot:run this command in project root directory that is /var/www/springboot_app/.
4. Build the Application (if needed)
If source code is uploaded:
./mvnw clean package -DskipTests
Final JAR will be in:
target/app.jar
5. Run Spring Boot Application (Basic)
Test the application before production setup:
java -jar target/app.jar
By default, it runs on port 8080.
Check:
curl http://localhost:8080
6. Run Application in Background (Production Ready)
Running manually is not a strategy. We use systemd for reliability.
Create service file:
sudo nano /etc/systemd/system/springboot.service
Paste:
[Unit]
Description=Spring Boot Application
After=network.target
[Service]
User=root
WorkingDirectory=/var/www/springboot_app
ExecStart=mvn spring-boot:run
SuccessExitStatus=143
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Note: Replace mvn spring-boot:run with you project start command. You may use /usr/bin/java -jar /var/www/springboot_app/target/app.jar commond in ExecStart=.
Reload systemd:
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
Start service:
sudo systemctl start springboot
sudo systemctl enable springboot
Check status:
sudo systemctl status springboot
7. Configure Nginx as Reverse Proxy
We don’t expose port 8080 publicly. We use Nginx.
Install Nginx:
sudo apt install -y nginx
Create config:
sudo nano /etc/nginx/sites-available/springboot
Paste:
server {
listen 80;
server_name example.com;
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;
}
}
Enable config:
sudo ln -s /etc/nginx/sites-available/springboot /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Restrict firewall:
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
Disable direct access to port 8080
8. Enable HTTPS with SSL (Certbot)
Secure applications build trust and improve ranking.
Install Certbot:
sudo apt install -y certbot python3-certbot-nginx
Generate SSL:
sudo certbot --nginx -d example.com
Auto-renewal is handled automatically.
9. Optimize Application Configuration
We configure Spring Boot for production.
Edit:
nano src/main/resources/application.properties
Recommended settings:
server.port=8080
server.address=0.0.0.0
spring.profiles.active=prod
server.tomcat.max-threads=200
server.connection-timeout=5s
Rebuild and restart:
sudo systemctl restart springboot
10. Logging and Monitoring
Check logs:
journalctl -u springboot -f
For file-based logging:
logging.file.name=/var/log/springboot/app.log
11. Performance and Memory Optimization
Run with controlled memory:
ExecStart=/usr/bin/java -Xms512m -Xmx1024m -jar /var/www/springboot_app/target/app.jar
Avoid unlimited memory usage. It will crash the server before it crashes itself.
12. Zero Downtime Deployment (Advanced)
Instead of killing the service:
sudo systemctl restart springboot
We can:
- Use blue-green deployment
- Run multiple instances
- Use load balancer (Nginx upstream)
Example:
upstream springboot_backend {
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
Final Thoughts
In this tutorial, we have learnt how how to run a Spring Boot application on a Linux server using Java. A stable deployment is not about running a JAR file. It is about control, monitoring, and predictability. With systemd, Nginx, and SSL in place, we ensure that our Spring Boot application is reliable, secure, and ready for production workloads.
This setup forms a solid base that can be extended with Docker, CI/CD pipelines, and cloud orchestration as we scale further.

