157 lines
4.5 KiB
Plaintext
157 lines
4.5 KiB
Plaintext
#===============================================================================
|
|
# iConsulting Nginx 配置
|
|
#
|
|
# 域名: iconsulting.szaiai.com
|
|
#
|
|
# 路由规则:
|
|
# / -> web-client (用户前端)
|
|
# /admin -> admin-client (管理后台)
|
|
# /api/v1/* -> Kong API Gateway
|
|
# /ws/* -> WebSocket (conversation-service)
|
|
#
|
|
#===============================================================================
|
|
|
|
# HTTP -> HTTPS 重定向
|
|
server {
|
|
listen 80;
|
|
server_name iconsulting.szaiai.com;
|
|
|
|
# Let's Encrypt 验证路径
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/certbot;
|
|
}
|
|
|
|
# 健康检查端点 (不重定向)
|
|
location /health {
|
|
access_log off;
|
|
return 200 'OK';
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
# 其他请求重定向到 HTTPS
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
# HTTPS 主服务
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name iconsulting.szaiai.com;
|
|
|
|
# SSL 证书配置
|
|
ssl_certificate /etc/nginx/ssl/fullchain.pem;
|
|
ssl_certificate_key /etc/nginx/ssl/privkey.pem;
|
|
|
|
# SSL 优化配置
|
|
ssl_session_timeout 1d;
|
|
ssl_session_cache shared:SSL:50m;
|
|
ssl_session_tickets off;
|
|
|
|
# 现代 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;
|
|
|
|
# HSTS (启用后浏览器会强制使用 HTTPS)
|
|
add_header Strict-Transport-Security "max-age=63072000" 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;
|
|
|
|
# 健康检查端点
|
|
location /health {
|
|
access_log off;
|
|
return 200 'OK';
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
# 用户前端 (web-client)
|
|
location / {
|
|
root /usr/share/nginx/html/web;
|
|
index index.html;
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
# 缓存静态资源
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
}
|
|
|
|
# 管理后台 (admin-client)
|
|
location /admin {
|
|
alias /usr/share/nginx/html/admin;
|
|
index index.html;
|
|
try_files $uri $uri/ /admin/index.html;
|
|
|
|
# 缓存静态资源
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
}
|
|
|
|
# API 请求代理到 Kong
|
|
location /api/ {
|
|
proxy_pass http://kong_upstream/;
|
|
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;
|
|
|
|
# 超时设置
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# 缓冲设置
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
}
|
|
|
|
# WebSocket 代理
|
|
location /ws/ {
|
|
proxy_pass http://websocket_upstream/;
|
|
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;
|
|
|
|
# WebSocket 超时 (保持长连接)
|
|
proxy_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
}
|
|
|
|
# Socket.IO 专用路径
|
|
location /socket.io/ {
|
|
proxy_pass http://websocket_upstream/socket.io/;
|
|
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_connect_timeout 7d;
|
|
proxy_send_timeout 7d;
|
|
proxy_read_timeout 7d;
|
|
}
|
|
|
|
# 禁止访问隐藏文件
|
|
location ~ /\. {
|
|
deny all;
|
|
access_log off;
|
|
log_not_found off;
|
|
}
|
|
}
|