94 lines
2.9 KiB
Nginx Configuration File
94 lines
2.9 KiB
Nginx Configuration File
worker_processes auto;
|
|
|
|
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
# Enable logging to see what's happening
|
|
error_log /dev/stderr warn;
|
|
access_log /dev/stdout;
|
|
|
|
# Gzip compression
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_min_length 256;
|
|
gzip_types
|
|
text/plain
|
|
text/css
|
|
text/xml
|
|
text/javascript
|
|
application/javascript
|
|
application/json
|
|
application/xml
|
|
application/rss+xml
|
|
image/svg+xml;
|
|
|
|
# Define rate limit zone: 10MB memory, 5 requests per second per IP
|
|
limit_req_zone $binary_remote_addr zone=ratelimit:10m rate=5r/s;
|
|
|
|
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
# Security headers for Lighthouse Best Practices
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
|
|
|
|
# Use Docker's internal DNS resolver with a short TTL
|
|
# This prevents caching stale IPs when containers are rebuilt
|
|
resolver 127.0.0.11 valid=10s;
|
|
set $upstream http://erika:3000;
|
|
|
|
# Timeouts for upstream connections
|
|
proxy_connect_timeout 10s;
|
|
proxy_read_timeout 30s;
|
|
proxy_send_timeout 10s;
|
|
proxy_next_upstream error timeout;
|
|
|
|
# Bypass rate limit for static assets and Next.js internal files
|
|
location /_next/static/ {
|
|
proxy_pass $upstream;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
|
|
# Cache static assets for 1 year (they have hashed filenames)
|
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
|
allow all;
|
|
}
|
|
|
|
location /_next/ {
|
|
proxy_pass $upstream;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
allow all;
|
|
}
|
|
|
|
# Apply rate limit to actual page loads and API requests
|
|
location / {
|
|
# Increased burst to 30 to allow normal page loads that fetch multiple APIs/images
|
|
limit_req zone=ratelimit burst=30 nodelay;
|
|
|
|
# Proxy to the Next.js app
|
|
proxy_pass $upstream;
|
|
|
|
# Next.js often requires HTTP/1.1
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
# Forward headers
|
|
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;
|
|
}
|
|
}
|
|
}
|