You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
5.4 KiB

3 weeks ago
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 {
3 weeks ago
listen 443 ssl;
http2 on;
3 weeks ago
server_name smartsensiguard.cn www.smartsensiguard.cn;
# SSL 证书配置
3 weeks ago
# 注意:如果证书文件包含完整证书链,直接使用 .pem 文件
# 如果证书和证书链是分开的,需要合并:cat cert.pem chain.pem > fullchain.pem
3 weeks ago
ssl_certificate /etc/nginx/ssl/smartsensiguard.cn.pem;
ssl_certificate_key /etc/nginx/ssl/smartsensiguard.cn.key;
3 weeks ago
# 如果证书链文件单独存在,取消下面的注释并指定路径
# ssl_trusted_certificate /etc/nginx/ssl/chain.pem;
3 weeks ago
3 weeks ago
# SSL 安全配置 - 兼容移动设备和Firefox
# 支持 TLS 1.2 和 1.3,确保移动设备兼容性
3 weeks ago
ssl_protocols TLSv1.2 TLSv1.3;
3 weeks ago
# 使用更兼容的密码套件,确保移动设备和Firefox支持
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:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA';
3 weeks ago
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_session_tickets off;
3 weeks ago
# SSL 优化配置
ssl_buffer_size 8k;
3 weeks ago
# 如果证书链不完整,OCSP Stapling 可能导致 Firefox 和移动设备无法验证
# 暂时禁用 OCSP Stapling 以提高兼容性
# 如果证书链完整,可以重新启用
ssl_stapling off;
ssl_stapling_verify off;
# resolver 8.8.8.8 8.8.4.4 valid=300s;
# resolver_timeout 5s;
3 weeks ago
3 weeks ago
# 安全头 - 兼容移动设备
3 weeks ago
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;
3 weeks ago
# 移动设备优化
# 确保移动设备可以正确解析内容类型
add_header Vary "Accept-Encoding" always;
3 weeks ago
# 反向代理到 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;
3 weeks ago
# 代理缓冲区配置(优化大文件传输)
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;
3 weeks ago
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
3 weeks ago
# 静态文件缓存(优化大图片文件)
3 weeks ago
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
proxy_pass http://marketing-site:3000;
3 weeks ago
# 静态文件专用缓冲区配置(更大的缓冲区)
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;
3 weeks ago
proxy_cache_valid 200 1d;
expires 1d;
add_header Cache-Control "public, immutable";
}
}
}