# Nginx Load Balancer Configuration Template # # This configuration is designed for use with the Load Balancer Configurator plugin. # It provides a basic setup for load balancing across multiple upstream servers. # # To use this template: # 1. Replace the placeholders with your actual server details. # 2. Choose the appropriate load balancing method. # 3. Test the configuration thoroughly before deploying to production. # User under which nginx runs user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; # Upstream servers - Replace these with your actual server details upstream backend { # Load balancing method: # - round-robin (default) # - least_conn # - ip_hash # - url_hash (requires nginx plus) # Example: least_conn; server : weight=5; # Replace with your server IP and port server : weight=5; # Replace with your server IP and port server : weight=3 backup; # Replace with your server IP and port, backup server } server { listen 80; # Listen on port 80 server_name ; # Replace with your domain name or IP address # Enforce HTTPS redirection # return 301 https://$host$request_uri; # Optional: Configure HTTPS in a separate server block location / { proxy_pass http://backend; # Proxy requests to the upstream servers 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; # Optional: Adjust timeouts for slow clients proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; } # Optional: Add error page configuration # error_page 500 502 503 504 /50x.html; # location = /50x.html { # root /usr/share/nginx/html; # } } # Optional: HTTPS Configuration (Requires SSL Certificates) # server { # listen 443 ssl http2; # server_name ; # Replace with your domain name # ssl_certificate /etc/nginx/ssl/.crt; # Replace with your certificate path # ssl_certificate_key /etc/nginx/ssl/.key; # Replace with your key path # ssl_session_cache shared:SSL:10m; # ssl_session_timeout 10m; # ssl_protocols TLSv1.2 TLSv1.3; # ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; # ssl_prefer_server_ciphers on; # location / { # proxy_pass http://backend; # 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; # } # } # Load configuration files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf; }