Files

42 lines
1.5 KiB
Nginx Configuration File
Raw Permalink 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.
# 前端 Nginx:托管 admin SPA 与采集 SDK,/api/ 反代 Django(compose 服务名 web)
# HTTPS 不在此终结:由 1Panel「网站」功能(OpenResty)反代本 80 端口或直接挂证书,
# 二选一即可,见 README-deploy.md 第 5 节。
server {
listen 80;
server_name _;
# gzip 压缩 js/css/json(SDK v1.js 体积小,不设 min_length 阈值)
gzip on;
gzip_comp_level 6;
gzip_types text/css application/javascript text/javascript application/json;
# Django API。client_max_body_size 与 settings DATA_UPLOAD_MAX_MEMORY_SIZE(256KB)对齐
location /api/ {
client_max_body_size 256k;
proxy_pass http://web:8000;
# XFF 透传上层(1Panel OpenResty 已追加真实客户端IP),勿再追加自身——
# 否则 Django 取末段会拿到 Docker 网关 IP(172.20.x.1),真实IP与地理位置全丢
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
}
# 采集 SDK(sdk/dist/v1.js)。no-cache:SDK 更新后及时生效
location /sdk/ {
alias /var/www/sdk/;
add_header Cache-Control "no-cache";
}
# 管理后台 SPA:路由 fallback 到 index.html
location / {
root /var/www/admin;
try_files $uri $uri/ /index.html;
}
# admin 构建产物带 hash 文件名,可长缓存
location /assets/ {
root /var/www/admin;
add_header Cache-Control "public, max-age=2592000, immutable";
}
}