Skip to content

Instantly share code, notes, and snippets.

@getsadzeg
Forked from vaso991/nginx
Created April 3, 2025 19:10
Show Gist options
  • Save getsadzeg/170134c0727e3ab6e9f70073c24217ea to your computer and use it in GitHub Desktop.
Save getsadzeg/170134c0727e3ab6e9f70073c24217ea to your computer and use it in GitHub Desktop.
upstream loadbalancer {
server localhost:3000;
server localhost:3001;
}
server {
listen 80;
listen [::]:80;
server_name api.example.com;
return 302 https://$server_name$request_uri;
}
server {
# SSL configuration
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/ssl/cert.pem;
ssl_certificate_key /etc/ssl/key.pem;
server_name api.example.com;
# Enable gzip compression only for application/json
gzip off;
gzip_types application/json;
gzip_proxied any;
gzip_min_length 1000;
gzip_vary on;
location / {
proxy_pass http://loadbalancer;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $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;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass_request_headers on;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment