2026-04-08
What We’ll Cover:
Learning Objectives:
Performance Benefits: - Serve static content directly - Cache responses - Gzip compression - Load balancing capability
Security Benefits: - Hide application server details - SSL termination - Request filtering - Security headers
Flow: Client → Nginx (Port 80) → Spring Boot (Port 8080)
Don’t forget: Also open ports 80 and 443 in Lightsail’s Networking tab!
Key Configuration Sections: - Server block and domain settings - Security headers - Gzip compression - Proxy settings
server {
listen 80;
server_name your-domain.com www.your-domain.com;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# Main application proxy
location / {
proxy_pass http://localhost: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;
}
}Benefits: Reduces bandwidth usage by up to 70%
# Add to /etc/nginx/nginx.conf http block
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=general:10m rate=1r/s;
# In server block
location /api/auth/login {
limit_req zone=login burst=3 nodelay;
proxy_pass http://localhost:8080;
}Protection against: DDoS attacks, brute force attempts, API abuse
sudo nginx -t to validateLog Locations: - /var/log/nginx/access.log - /var/log/nginx/error.log
Best Practices: - Regular log rotation - Monitor system resources - Track response times - Set up alerting
{.incremental} - Enable gzip compression for text content - Set appropriate cache headers for static assets - Use separate location blocks for different content types - Implement connection keep-alive for better performance - Configure proper timeout values - Monitor and tune worker processes
What We Accomplished: - ✅ Installed and configured Nginx as reverse proxy - ✅ Implemented security headers and rate limiting - ✅ Optimized performance with compression and caching - ✅ Set up proper error handling and monitoring
Key Benefits: - Enhanced security and performance - Professional error handling - Production-ready architecture - Better monitoring and maintenance
Coming Up in Step 6: - Add custom domain configuration - Implement SSL/TLS certificates - Configure HTTPS redirects - Final security hardening
Your application is now: - Accessible through Nginx on port 80 - Protected with security headers - Optimized for performance - Ready for domain and SSL setup