Why put Nginx in front of Spring Boot instead of exposing the application to the Internet directly?
Short answer
Embedded Tomcat can face the Internet directly, but Nginx does the edge jobs better: TLS termination, static files, buffering slow clients, compression, rate limiting, load balancing across instances. The app listens only on internal port 8080 and handles business logic.
3 points to say:
- Nginx handles TLS, static files, slow-client buffering, compression, rate limiting, load balancing; slow clients don't hold Tomcat threads.
- Security: Nginx owns ports 80/443, the JVM runs as a regular user on 8080; hide the
Serverheader and Tomcat error pages. - Configure forwarded headers on both sides (Nginx sends, Spring Boot reads), and the app still needs its own timeouts.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.