Skip to content

Instantly share code, notes, and snippets.

@cometofsky
Last active December 9, 2024 16:07
Show Gist options
  • Save cometofsky/c8654b9144281edef3101a8bfed1f4bb to your computer and use it in GitHub Desktop.
Save cometofsky/c8654b9144281edef3101a8bfed1f4bb to your computer and use it in GitHub Desktop.
simple nginx configuration file for load balancing requests to multiple servers
# Main context (this is the global configuration)
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
# Upstream block to define the Node.js backend servers
upstream nodejs_cluster {
server 127.0.0.1:3001;
server 127.0.0.1:3002;
server 127.0.0.1:3003;
}
server {
listen 443 ssl; # Listen on port 443 for HTTPS
server_name localhost;
# SSL certificate settings
ssl_certificate /Users/nana/nginx-certs/nginx-selfsigned.crt;
ssl_certificate_key /Users/nana/nginx-certs/nginx-selfsigned.key;
# Proxying requests to Node.js cluster
location / {
proxy_pass http://nodejs_cluster;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
# Optional server block for HTTP to HTTPS redirection
server {
listen 8080; # Listen on port 80 for HTTP
server_name localhost;
# Redirect all HTTP traffic to HTTPS
location / {
return 301 https://$host$request_uri;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment