153 lines
4.9 KiB
Plaintext
153 lines
4.9 KiB
Plaintext
# Production Nginx Configuration
|
|||
|
|
worker_processes auto;
|
||
|
|
error_log /var/log/nginx/error.log warn;
|
||
|
|
pid /var/run/nginx.pid;
|
||
|
|
|
||
|
|
events {
|
||
|
|
worker_connections 2048;
|
||
|
|
}
|
||
|
|
|
||
|
|
http {
|
||
|
|
include /etc/nginx/mime.types;
|
||
|
|
default_type application/octet-stream;
|
||
|
|
|
||
|
|
log_format production '$remote_addr - $remote_user [$time_local] "$request" '
|
||
|
|
'$status $body_bytes_sent "$http_referer" '
|
||
|
|
'"$http_user_agent" "$http_x_forwarded_for" '
|
||
|
|
'rt=$request_time';
|
||
|
|
|
||
|
|
access_log /var/log/nginx/access.log production;
|
||
|
|
|
||
|
|
sendfile on;
|
||
|
|
tcp_nopush on;
|
||
|
|
tcp_nodelay on;
|
||
|
|
keepalive_timeout 65;
|
||
|
|
types_hash_max_size 2048;
|
||
|
|
|
||
|
|
# Gzip
|
||
|
|
gzip on;
|
||
|
|
gzip_vary on;
|
||
|
|
gzip_min_length 1024;
|
||
|
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss;
|
||
|
|
|
||
|
|
# Rate limiting
|
||
|
|
limit_req_zone $binary_remote_addr zone=api:10m rate=50r/s;
|
||
|
|
limit_req_zone $binary_remote_addr zone=auth:10m rate=10r/s;
|
||
|
|
limit_req_zone $binary_remote_addr zone=upload:10m rate=5r/s;
|
||
|
|
limit_req_zone $binary_remote_addr zone=ws:10m rate=20r/s;
|
||
|
|
|
||
|
|
# Maintenance mode flag
|
||
|
|
map $http_x_maintenance_mode $maintenance_mode {
|
||
|
|
default 0;
|
||
|
|
"1" 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
upstream backend {
|
||
|
|
server backend:8080;
|
||
|
|
}
|
||
|
|
|
||
|
|
# HTTP -> HTTPS redirect (uncomment for production)
|
||
|
|
# server {
|
||
|
|
# listen 80;
|
||
|
|
# server_name match.danyang.gov.cn;
|
||
|
|
# return 301 https://$server_name$request_uri;
|
||
|
|
# }
|
||
|
|
|
||
|
|
server {
|
||
|
|
listen 443 ssl http2;
|
||
|
|
server_name match.danyang.gov.cn;
|
||
|
|
|
||
|
|
# SSL
|
||
|
|
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;
|
||
|
|
ssl_prefer_server_ciphers on;
|
||
|
|
ssl_session_cache shared:SSL:10m;
|
||
|
|
ssl_session_timeout 10m;
|
||
|
|
|
||
|
|
# Security headers
|
||
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||
|
|
add_header X-Frame-Options "DENY" always;
|
||
|
|
add_header X-Content-Type-Options "nosniff" always;
|
||
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
||
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' wss:;" always;
|
||
|
|
|
||
|
|
# Maintenance mode
|
||
|
|
location = /maintenance {
|
||
|
|
return 503 '<h1>系统维护中</h1><p>请稍后再访问。</p>';
|
||
|
|
}
|
||
|
|
|
||
|
|
# Health checks (no auth needed)
|
||
|
|
location = /api/v1/health/live {
|
||
|
|
proxy_pass http://backend;
|
||
|
|
proxy_set_header Host $host;
|
||
|
|
}
|
||
|
|
location = /api/v1/health/ready {
|
||
|
|
proxy_pass http://backend;
|
||
|
|
proxy_set_header Host $host;
|
||
|
|
}
|
||
|
|
location = /version {
|
||
|
|
proxy_pass http://backend;
|
||
|
|
proxy_set_header Host $host;
|
||
|
|
}
|
||
|
|
|
||
|
|
# Admin Web (SPA)
|
||
|
|
location /admin/ {
|
||
|
|
alias /usr/share/nginx/html/;
|
||
|
|
try_files $uri $uri/ /admin/index.html;
|
||
|
|
}
|
||
|
|
|
||
|
|
# API proxy
|
||
|
|
location /api/ {
|
||
|
|
limit_req zone=api burst=100 nodelay;
|
||
|
|
proxy_pass http://backend;
|
||
|
|
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_connect_timeout 30s;
|
||
|
|
proxy_send_timeout 60s;
|
||
|
|
proxy_read_timeout 60s;
|
||
|
|
}
|
||
|
|
|
||
|
|
# WebSocket proxy
|
||
|
|
location /ws/ {
|
||
|
|
limit_req zone=ws burst=20 nodelay;
|
||
|
|
proxy_pass http://backend;
|
||
|
|
proxy_http_version 1.1;
|
||
|
|
proxy_set_header Upgrade $http_upgrade;
|
||
|
|
proxy_set_header Connection "upgrade";
|
||
|
|
proxy_set_header Host $host;
|
||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
||
|
|
proxy_read_timeout 3600s;
|
||
|
|
}
|
||
|
|
|
||
|
|
# Auth endpoints (strict rate limiting)
|
||
|
|
location ~* ^/api/v1/auth/ {
|
||
|
|
limit_req zone=auth burst=5 nodelay;
|
||
|
|
proxy_pass http://backend;
|
||
|
|
proxy_set_header Host $host;
|
||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
||
|
|
}
|
||
|
|
|
||
|
|
# Upload endpoints
|
||
|
|
location ~* ^/api/v1/photos/upload {
|
||
|
|
limit_req zone=upload burst=5 nodelay;
|
||
|
|
client_max_body_size 10M;
|
||
|
|
proxy_pass http://backend;
|
||
|
|
proxy_set_header Host $host;
|
||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
||
|
|
}
|
||
|
|
|
||
|
|
# MinIO public bucket (read-only)
|
||
|
|
location /uploads/ {
|
||
|
|
proxy_pass http://backend/;
|
||
|
|
proxy_set_header Host $host;
|
||
|
|
expires 7d;
|
||
|
|
add_header Cache-Control "public, immutable";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|