|
|
|
|
user nginx;
|
|
|
|
|
worker_processes auto;
|
|
|
|
|
error_log /var/log/nginx/error.log warn;
|
|
|
|
|
pid /var/run/nginx.pid;
|
|
|
|
|
|
|
|
|
|
events {
|
|
|
|
|
worker_connections 1024;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http {
|
|
|
|
|
include /etc/nginx/mime.types;
|
|
|
|
|
default_type application/octet-stream;
|
|
|
|
|
|
|
|
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
|
|
|
'$status $body_bytes_sent "$http_referer" '
|
|
|
|
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
|
|
|
|
|
|
|
|
access_log /var/log/nginx/access.log main;
|
|
|
|
|
|
|
|
|
|
sendfile on;
|
|
|
|
|
tcp_nopush on;
|
|
|
|
|
tcp_nodelay on;
|
|
|
|
|
keepalive_timeout 65;
|
|
|
|
|
types_hash_max_size 2048;
|
|
|
|
|
client_max_body_size 20M;
|
|
|
|
|
|
|
|
|
|
# Gzip 压缩
|
|
|
|
|
gzip on;
|
|
|
|
|
gzip_vary on;
|
|
|
|
|
gzip_proxied any;
|
|
|
|
|
gzip_comp_level 6;
|
|
|
|
|
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
|
|
|
|
|
|
|
|
|
|
# HTTP 服务器 - 重定向到 HTTPS
|
|
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name smartsensiguard.cn www.smartsensiguard.cn;
|
|
|
|
|
|
|
|
|
|
# 允许 Let's Encrypt 验证
|
|
|
|
|
location /.well-known/acme-challenge/ {
|
|
|
|
|
root /var/www/certbot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 重定向所有 HTTP 请求到 HTTPS
|
|
|
|
|
location / {
|
|
|
|
|
return 301 https://$host$request_uri;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# HTTPS 服务器
|
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
|
|
|
|
http2 on;
|
|
|
|
|
server_name smartsensiguard.cn www.smartsensiguard.cn;
|
|
|
|
|
|
|
|
|
|
# SSL 证书配置
|
|
|
|
|
# 注意:如果证书文件包含完整证书链,直接使用 .pem 文件
|
|
|
|
|
# 如果证书和证书链是分开的,需要合并:cat cert.pem chain.pem > fullchain.pem
|
|
|
|
|
ssl_certificate /etc/nginx/ssl/smartsensiguard.cn.pem;
|
|
|
|
|
ssl_certificate_key /etc/nginx/ssl/smartsensiguard.cn.key;
|
|
|
|
|
|
|
|
|
|
# 如果证书链文件单独存在,取消下面的注释并指定路径
|
|
|
|
|
# ssl_trusted_certificate /etc/nginx/ssl/chain.pem;
|
|
|
|
|
|
|
|
|
|
# SSL 安全配置
|
|
|
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
|
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
|
|
|
|
|
ssl_prefer_server_ciphers off;
|
|
|
|
|
ssl_session_cache shared:SSL:10m;
|
|
|
|
|
ssl_session_timeout 10m;
|
|
|
|
|
ssl_session_tickets off;
|
|
|
|
|
|
|
|
|
|
# SSL 优化配置
|
|
|
|
|
ssl_buffer_size 8k;
|
|
|
|
|
ssl_stapling on;
|
|
|
|
|
ssl_stapling_verify on;
|
|
|
|
|
resolver 8.8.8.8 8.8.4.4 valid=300s;
|
|
|
|
|
resolver_timeout 5s;
|
|
|
|
|
|
|
|
|
|
# 安全头
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
|
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
|
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
|
|
|
|
|
|
|
|
# 反向代理到 Next.js 应用
|
|
|
|
|
location / {
|
|
|
|
|
proxy_pass http://marketing-site:3000;
|
|
|
|
|
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_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
proxy_cache_bypass $http_upgrade;
|
|
|
|
|
|
|
|
|
|
# 代理缓冲区配置(优化大文件传输)
|
|
|
|
|
proxy_buffer_size 16k;
|
|
|
|
|
proxy_buffers 8 16k;
|
|
|
|
|
proxy_busy_buffers_size 32k;
|
|
|
|
|
proxy_temp_file_write_size 64k;
|
|
|
|
|
proxy_max_temp_file_size 1024m;
|
|
|
|
|
|
|
|
|
|
# 超时设置
|
|
|
|
|
proxy_connect_timeout 60s;
|
|
|
|
|
proxy_send_timeout 60s;
|
|
|
|
|
proxy_read_timeout 60s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 静态文件缓存(优化大图片文件)
|
|
|
|
|
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
|
|
|
|
|
proxy_pass http://marketing-site:3000;
|
|
|
|
|
|
|
|
|
|
# 静态文件专用缓冲区配置(更大的缓冲区)
|
|
|
|
|
proxy_buffer_size 32k;
|
|
|
|
|
proxy_buffers 16 32k;
|
|
|
|
|
proxy_busy_buffers_size 64k;
|
|
|
|
|
proxy_temp_file_write_size 128k;
|
|
|
|
|
proxy_max_temp_file_size 2048m;
|
|
|
|
|
|
|
|
|
|
# 启用直接传输,减少内存使用
|
|
|
|
|
proxy_request_buffering off;
|
|
|
|
|
|
|
|
|
|
proxy_cache_valid 200 1d;
|
|
|
|
|
expires 1d;
|
|
|
|
|
add_header Cache-Control "public, immutable";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|