165 lines
4.5 KiB
Plaintext
165 lines
4.5 KiB
Plaintext
# H3C ONU设备管理系统 - Nginx站点配置
|
|
|
|
# 前端静态文件服务
|
|
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
# 根目录指向前端构建文件
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# Gzip压缩
|
|
gzip_static on;
|
|
|
|
# 静态文件缓存
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
access_log off;
|
|
}
|
|
|
|
# 前端路由支持 (Vue Router history模式)
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
expires -1;
|
|
add_header Cache-Control "no-store, no-cache, must-revalidate";
|
|
}
|
|
|
|
# API代理到后端
|
|
location /api/ {
|
|
proxy_pass http://backend:8000;
|
|
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_set_header X-Forwarded-Host $host;
|
|
proxy_set_header X-Forwarded-Port $server_port;
|
|
|
|
# 超时设置
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# 缓冲区设置
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
proxy_busy_buffers_size 8k;
|
|
|
|
# 禁用代理缓存
|
|
proxy_cache off;
|
|
}
|
|
|
|
# WebSocket支持
|
|
location /ws/ {
|
|
proxy_pass http://backend:8000;
|
|
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;
|
|
|
|
# WebSocket超时设置
|
|
proxy_read_timeout 3600s;
|
|
proxy_send_timeout 3600s;
|
|
}
|
|
|
|
# 静态文件代理 (后端静态文件)
|
|
location /static/ {
|
|
alias /usr/share/nginx/static/;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
access_log off;
|
|
}
|
|
|
|
# 健康检查端点
|
|
location /health {
|
|
proxy_pass http://backend:8000/health;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
access_log off;
|
|
}
|
|
|
|
# 监控指标端点
|
|
location /metrics {
|
|
proxy_pass http://backend:8000/metrics;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
access_log off;
|
|
}
|
|
|
|
# API文档
|
|
location /docs {
|
|
proxy_pass http://backend:8000/docs;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
}
|
|
|
|
location /redoc {
|
|
proxy_pass http://backend:8000/redoc;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
}
|
|
|
|
# 错误页面
|
|
error_page 404 /index.html;
|
|
error_page 500 502 503 504 /50x.html;
|
|
|
|
location = /50x.html {
|
|
root /usr/share/nginx/html;
|
|
}
|
|
}
|
|
|
|
# HTTPS配置 (需要SSL证书)
|
|
# server {
|
|
# listen 443 ssl http2;
|
|
# server_name your-domain.com;
|
|
#
|
|
# # SSL证书配置
|
|
# ssl_certificate /etc/nginx/ssl/your-domain.com.crt;
|
|
# ssl_certificate_key /etc/nginx/ssl/your-domain.com.key;
|
|
#
|
|
# # SSL优化配置
|
|
# ssl_protocols TLSv1.2 TLSv1.3;
|
|
# ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
|
|
# ssl_prefer_server_ciphers off;
|
|
# ssl_session_cache shared:SSL:10m;
|
|
# ssl_session_timeout 10m;
|
|
#
|
|
# # HSTS头
|
|
# add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
#
|
|
# # 其他配置与HTTP相同
|
|
# root /usr/share/nginx/html;
|
|
# index index.html;
|
|
#
|
|
# location / {
|
|
# try_files $uri $uri/ /index.html;
|
|
# }
|
|
#
|
|
# location /api/ {
|
|
# proxy_pass http://backend:8000;
|
|
# # ... 其他代理配置
|
|
# }
|
|
#
|
|
# # 强制HTTP重定向到HTTPS
|
|
# # if ($scheme != "https") {
|
|
# # return 301 https://$host$request_uri;
|
|
# # }
|
|
# }
|
|
|
|
# 重定向HTTP到HTTPS (如果启用HTTPS)
|
|
# server {
|
|
# listen 80;
|
|
# server_name your-domain.com;
|
|
# return 301 https://$server_name$request_uri;
|
|
# } |