#=============================================================================== # iConsulting Docker Nginx 配置 # # 注意: 此 Nginx 运行在 Docker 容器内,监听 80 端口 # 系统 Nginx 负责 SSL 终止,然后反向代理到此处 # # 路由规则: # / -> 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/ { # 使用变量实现动态解析,避免启动时服务不可用导致失败 set $kong_upstream kong:8000; 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/ { set $ws_upstream conversation-service:3004; proxy_pass http://$ws_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/ { set $ws_upstream conversation-service:3004; proxy_pass http://$ws_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; } }