Blueprints · Reverse Proxy & SSL
Beginner
15 min · Nginx
Static site and SPA Nginx template
Serves an Astro or React build with gzip, a long cache on hashed assets, an SPA fallback, and a strict content security policy.
Live config
Baked-in protections
- Hashed assets are immutable for a year
- Unknown paths fall back to index.html
- CSP defaults to self and blocks framing
- gzip is enabled for text responses
- Brotli is used only when the nginx module is already installed
Step 1 · nginx
Nginx site
/etc/nginx/sites-available/www.example.com.conf
Point APP_PATH at the built dist or out directory, not the source tree.
server {
listen 80;
server_name www.example.com;
root /var/www/site;
server_tokens off;
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
add_header Content-Security-Policy "default-src 'self'; frame-ancestors 'none'; base-uri 'self'" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
location /assets/ {
try_files $uri =404;
add_header Cache-Control "public, max-age=31536000, immutable";
}
location / {
try_files $uri $uri/ /index.html;
}
}
Step 2 · bash
Enable the site
/root/portgate-blueprints/static-enable.sh
Enables the brotli directives only when that module is present, so a stock Nginx still reloads.
#!/bin/sh set -eu install -d -m 755 "/var/www/site" if nginx -V 2>&1 | grep -q brotli; then printf '%s\n' 'brotli on;' 'brotli_types text/css application/javascript application/json image/svg+xml;' > /etc/nginx/conf.d/portgate-brotli.conf fi ln -sfn "/etc/nginx/sites-available/www.example.com.conf" /etc/nginx/sites-enabled/www.example.com.conf nginx -t systemctl reload nginx