Java Apps Behind Load Balancers
Java web applications — particularly Spring Boot — need explicit proxy configuration when deployed behind a load balancer. Without it, redirect URLs are wrong and session management breaks.
Spring Boot Proxy Headers
Tell Spring Boot to trust forwarded headers:
# application.yml
server:
forward-headers-strategy: framework
tomcat:
remoteip:
remote-ip-header: X-Forwarded-For
protocol-header: X-Forwarded-ProtoOr in newer Spring Boot versions, simply:
server:
forward-headers-strategy: nativeSession Stickiness
If you use HTTP sessions, either enable sticky sessions on the load balancer or externalize sessions:
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>spring:
session:
store-type: redis
redis:
host: redis-serviceHealth Check Actuator
Spring Boot Actuator provides health endpoints out of the box:
management:
endpoints:
web:
exposure:
include: health
endpoint:
health:
show-details: neverPoint the load balancer at /actuator/health.
Timeout Alignment
The load balancer timeout must be shorter than the server's:
server:
connection-timeout: 120000 # 120 secondsSet ALB idle timeout to 90 seconds so it closes the connection before Tomcat does, preventing 502 errors.
Bugsly's Java SDK auto-captures exceptions with request context including the original client IP from X-Forwarded-For, so errors are attributed to real users, not the load balancer.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
How to Fix Generator Error in Node.js
Learn how to fix the Generator Error in Node.js. Step-by-step guide with code examples.
Read moreFix Load Balancer Error in Ruby
Resolve load balancer issues for Ruby web apps using Sinatra, Rack, or Puma, covering proxy headers and connection keep-alive settings.
Read moreFix Connection Refused Error in Remix
Learn how to fix the Connection Refused error in Remix. Step-by-step guide with code examples and solutions. Quick, practical guide for developers.
Read moreFix Connection Refused Error in Rails
Learn how to fix the Connection Refused error in Rails. Step-by-step guide with code examples and solutions. Quick, practical guide for developers.
Read more