131 lines
3.7 KiB
Plaintext
131 lines
3.7 KiB
Plaintext
#===============================================================================
|
||
# iConsulting Nginx 配置
|
||
#
|
||
# 路由规则:
|
||
# / -> web-client (用户前端)
|
||
# /admin -> admin-client (管理后台)
|
||
# /api/v1/* -> Kong API Gateway
|
||
# /ws/* -> WebSocket (conversation-service)
|
||
#
|
||
#===============================================================================
|
||
|
||
server {
|
||
listen 80;
|
||
server_name _;
|
||
|
||
# 健康检查端点
|
||
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;
|
||
}
|
||
}
|
||
|
||
# HTTPS 配置 (如有SSL证书,取消注释)
|
||
# server {
|
||
# listen 443 ssl http2;
|
||
# server_name _;
|
||
#
|
||
# ssl_certificate /etc/nginx/ssl/fullchain.pem;
|
||
# ssl_certificate_key /etc/nginx/ssl/privkey.pem;
|
||
# ssl_session_timeout 1d;
|
||
# ssl_session_cache shared:SSL:50m;
|
||
# ssl_session_tickets off;
|
||
#
|
||
# ssl_protocols TLSv1.2 TLSv1.3;
|
||
# ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
|
||
# ssl_prefer_server_ciphers off;
|
||
#
|
||
# # HSTS
|
||
# add_header Strict-Transport-Security "max-age=63072000" always;
|
||
#
|
||
# # 其他配置同上...
|
||
# include /etc/nginx/conf.d/locations.conf;
|
||
# }
|