All checks were successful
Web UI CI/CD / build-and-deploy (push) Successful in 3m23s
55 lines
1.8 KiB
Nginx Configuration File
55 lines
1.8 KiB
Nginx Configuration File
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 容器中,使用容器名:http://aiot-server:48080
|
||
# 如果后端在宿主机上,使用内网地址:http://172.17.16.14:48080 或 http://172.17.0.1:48080
|
||
location /admin-api {
|
||
proxy_pass http://172.17.16.14:48080/admin-api;
|
||
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;
|
||
}
|
||
}
|
||
|