Files
aiot-platform-ui/apps/web-antd/nginx.conf
lzh 874c06fa51
All checks were successful
Web UI CI/CD / build-and-deploy (push) Successful in 3m31s
fix: 优化构建速度,后端容器名
2025-12-18 14:03:54 +08:00

66 lines
2.2 KiB
Nginx Configuration File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

server {
listen 80;
server_name localhost; # 通配符,匹配所有域名(适用于反向代理场景)
# 开启 gzip 压缩
gzip on;
gzip_min_length 1k;
gzip_comp_level 6;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
root /usr/share/nginx/html;
index index.html;
# API 反向代理到后端服务
# 后端服务在 Docker 容器中,使用容器名访问(都在 aiot-net 网络中)
# 如果后端在宿主机上改为http://172.17.0.1:48080/admin-api
location /admin-api {
# 后端服务地址(根据实际情况选择)
# 方案1后端在 Docker 容器中(推荐)
proxy_pass http://aiot-server:48080/admin-api;
# 方案2后端在宿主机上取消注释下面这行并注释掉上面那行
# proxy_pass http://172.17.0.1:48080/admin-api;
# 代理超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
# 代理请求头
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;
# 解决跨域问题
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
# 处理 OPTIONS 预检请求
if ($request_method = 'OPTIONS') {
return 204;
}
}
# 解决 SPA 路由刷新 404 问题
location / {
try_files $uri $uri/ /index.html;
}
# 静态资源缓存配置
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
}
# 错误页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}