Files
freedom-web/nginx.conf
T
张家训 ac3584e159
CI/CD Deploy (Web) / 构建前端镜像并部署 (push) Successful in 23s
feat(perf): nginx 开启 gzip,降低 frp 隧道传输量
- 现状:chunk-vendors.js 2.4MB 未压缩原样传输,单次页面加载 4.5MB/50s
- gzip level 5,min_length 1KB,覆盖 js/css/json/svg/woff 等类型
- 压缩率约 75-80%,页面加载量降至 ~1MB
2026-10-20 17:05:02 +08:00

131 lines
4.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.
# =============================================================
# freedom 统一入口 Nginx 配置
# 同一域名路径区分:/api/* 反代到后端容器,其余走前端静态文件
#
# 后端接口无 /api 前缀,因此需要去掉前缀再转发。
# 后端容器服务名:backend,端口:8800(见 docker-compose.yml)
# =============================================================
# ---------------- gzip 压缩(frp 隧道带宽受限,压缩是关键) ----------------
# 2.4MB 的 chunk-vendors.js 压缩后约 500KB,传输量整体可降 75%+
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_types
text/plain
text/css
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
image/svg+xml
font/woff
font/woff2;
# -------------------------------------------------------------
# todo.jiaxun.site:公开待办看板专用域名
# 根路径直接出看板页;SPA 兜底也指向看板页(该域名下无 freedom 路由)
# 前提:上游(VPS openresty)反代时需传 Host 头(proxy_set_header Host $host)
# -------------------------------------------------------------
server {
listen 80;
server_name todo.jiaxun.site;
root /usr/share/nginx/html;
index todo-public.html;
client_max_body_size 20m;
# /api/xxx -> backend:8800/xxx(与主站一致,去掉 /api 前缀)
location /api/ {
proxy_pass http://backend:8800/;
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_set_header Authorization $http_authorization;
proxy_connect_timeout 10s;
proxy_read_timeout 60s;
}
# 根路径:内部重写到看板页,地址栏保持域名根路径
location = / {
try_files /todo-public.html =404;
}
# 其余路径:真实文件优先,兜底到看板页
location / {
try_files $uri $uri/ /todo-public.html;
}
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico|woff2?|ttf|eot)$ {
expires 7d;
add_header Cache-Control "public, max-age=604800";
try_files $uri =404;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
# ---------------- 主站(IP:8880 及其他域名直达) ----------------
server {
listen 80 default_server;
server_name _;
root /usr/share/nginx/html;
index index.html;
# 请求体大小限制(如有文件上传需求可调大)
client_max_body_size 20m;
# ---------------- API 反向代理 ----------------
# /api/xxx -> backend:8800/xxx (去掉 /api 前缀)
location /api/ {
proxy_pass http://backend:8800/;
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_set_header Authorization $http_authorization;
proxy_connect_timeout 10s;
proxy_read_timeout 60s;
}
# ---------------- Excel 模板静态文件 ----------------
# 前端 nginxPath 指向 /excelTemplate.xxx,放在 Nginx 根目录静态文件
location = /excelTemplate {
alias /usr/share/nginx/html/;
}
location ~ ^/excelTemplate\.[a-zA-Z0-9]+$ {
try_files $uri =404;
}
# ---------------- 前端静态资源 + SPA 路由 ----------------
location / {
try_files $uri $uri/ /index.html;
}
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico|woff2?|ttf|eot)$ {
expires 7d;
add_header Cache-Control "public, max-age=604800";
try_files $uri =404;
}
# 常见接口错误页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}