Loading...
Generate an Nginx server block — reverse proxy or static/SPA, TLS with HTTP→HTTPS redirect, load balancing, gzip, security headers, and rate limiting.
# --- put these in the http { } context ---
gzip on;
gzip_types text/plain text/css application/json application/javascript image/svg+xml;
server {
listen 80;
server_name app.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
http2 on;
server_name app.example.com;
ssl_certificate /etc/nginx/certs/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 10m;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options DENY always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
location / {
proxy_pass http://127.0.0.1:3000;
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;
proxy_read_timeout 60s;
}
}
Drop this in /etc/nginx/conf.d/, run nginx -t, then nginx -s reload. Learn the directives in the Nginx tutorial.