Implement zero-downtime deployment strategy
- Add rolling update mechanism for seamless deployments - Start new container on port 3001, health check, then switch - Preserve database and redis connections during updates - Automatic fallback to fresh deployment if no current container - Add advanced nginx load balancer configuration for future use - Eliminate container name conflicts with proper cleanup - Website stays online during deployments
This commit is contained in:
62
nginx-zero-downtime.conf
Normal file
62
nginx-zero-downtime.conf
Normal file
@@ -0,0 +1,62 @@
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
upstream portfolio_backend {
|
||||
# Health check enabled upstream
|
||||
server portfolio-app-1:3000 max_fails=3 fail_timeout=30s;
|
||||
server portfolio-app-2:3000 max_fails=3 fail_timeout=30s;
|
||||
}
|
||||
|
||||
# Health check endpoint
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "healthy\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
||||
|
||||
# Main server
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
# Proxy settings
|
||||
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;
|
||||
|
||||
# Timeout settings
|
||||
proxy_connect_timeout 5s;
|
||||
proxy_send_timeout 60s;
|
||||
proxy_read_timeout 60s;
|
||||
|
||||
# Buffer settings
|
||||
proxy_buffering on;
|
||||
proxy_buffer_size 4k;
|
||||
proxy_buffers 8 4k;
|
||||
|
||||
# Main location
|
||||
location / {
|
||||
proxy_pass http://portfolio_backend;
|
||||
|
||||
# Health check for upstream
|
||||
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
|
||||
proxy_next_upstream_tries 2;
|
||||
proxy_next_upstream_timeout 10s;
|
||||
}
|
||||
|
||||
# Static files caching
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
proxy_pass http://portfolio_backend;
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user