# NewAPI Nginx 反向代理配置示例 # 请根据实际情况修改域名和SSL证书路径 upstream newapi_backend { server 127.0.0.1:3000; # 如果有多个实例,可以添加更多server # server 127.0.0.1:3001; } # HTTP重定向到HTTPS server { listen 80; server_name your-domain.com www.your-domain.com; # Let's Encrypt证书验证路径 location /.well-known/acme-challenge/ { root /var/www/html; } # 其他请求重定向到HTTPS location / { return 301 https://$server_name$request_uri; } } # HTTPS配置 server { listen 443 ssl http2; server_name your-domain.com www.your-domain.com; # SSL证书配置 ssl_certificate /etc/ssl/certs/your-domain.com.crt; ssl_certificate_key /etc/ssl/private/your-domain.com.key; # SSL安全配置 ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384; ssl_prefer_server_ciphers off; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; # 安全头 add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header Referrer-Policy "strict-origin-when-cross-origin"; # 客户端最大上传大小 client_max_body_size 10M; # 代理配置 location / { proxy_pass http://newapi_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_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade; # 超时设置 proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; # 缓冲设置 proxy_buffering on; proxy_buffer_size 4k; proxy_buffers 8 4k; } # 静态文件缓存 location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { proxy_pass http://newapi_backend; expires 1y; add_header Cache-Control "public, immutable"; add_header Vary Accept-Encoding; } # API请求特殊处理 location /api/ { proxy_pass http://newapi_backend; proxy_http_version 1.1; 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; # API请求超时设置(可能需要更长时间) proxy_connect_timeout 120s; proxy_send_timeout 120s; proxy_read_timeout 120s; } # 健康检查 location /health { proxy_pass http://newapi_backend/api/status; access_log off; } }