From 494c9aec0ec99d501fea2f1102444ebe7dc6c280 Mon Sep 17 00:00:00 2001 From: "douboer@gmail.com" Date: Wed, 11 Feb 2026 17:32:09 +0800 Subject: [PATCH] update at 2026-02-11 17:32:09 --- font2svg.mac.conf | 150 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 font2svg.mac.conf diff --git a/font2svg.mac.conf b/font2svg.mac.conf new file mode 100644 index 0000000..6da8861 --- /dev/null +++ b/font2svg.mac.conf @@ -0,0 +1,150 @@ +# Font2SVG - Mac Nginx 配置(mac.biboer.cn / mac-tunnel.biboer.cn) +# 用途: +# 1) 为微信小程序提供字体清单、默认配置、路由配置与渲染 API +# 2) 提供 Web 应用静态页面(frontend/dist) + +server { + listen 80; + listen [::]:80; + server_name mac.biboer.cn; + return 301 https://$host:8443$request_uri; +} + +# Cloudflare Tunnel 入口(推荐): +# 外部 https://mac-tunnel.biboer.cn(443) -> cloudflared -> 本机 80(Nginx) +server { + listen 80; + listen [::]:80; + server_name mac-tunnel.biboer.cn; + + # 项目根目录(包含 fonts/、fonts.json、miniprogram/assets/*、frontend/dist/*) + root /Users/gavin/font2svg; + index index.html; + + access_log /opt/homebrew/var/log/nginx/access.log; + error_log /opt/homebrew/var/log/nginx/error.log; + + server_tokens off; + + # 小程序跨域访问 + add_header Access-Control-Allow-Origin "*" always; + add_header Access-Control-Allow-Methods "GET,HEAD,POST,OPTIONS" always; + add_header Access-Control-Allow-Headers "Origin,Range,Accept,Content-Type,Authorization" always; + add_header Access-Control-Expose-Headers "Content-Length,Content-Range" always; + + # MIME + types { + application/json json; + font/ttf ttf; + font/otf otf; + font/woff woff; + font/woff2 woff2; + application/vnd.ms-fontobject eot; + } + + # SVG 渲染 API(独立 Python 服务,监听 127.0.0.1:9300) + location ^~ /api/ { + if ($request_method = OPTIONS) { + return 204; + } + proxy_pass http://127.0.0.1:9300; + 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_connect_timeout 5s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + } + + # 健康检查 + location = /healthz { + proxy_pass http://127.0.0.1:9300/healthz; + 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; + } + + # -------------------- 小程序静态配置 -------------------- + + # 字体清单:短缓存,便于更新 + location = /fonts.json { + expires 1h; + add_header Cache-Control "public, must-revalidate" always; + try_files $uri =404; + } + + location = /miniprogram/assets/fonts.json { + expires 1h; + add_header Cache-Control "public, must-revalidate" always; + try_files $uri =404; + } + + location = /miniprogram/assets/default.json { + expires 1h; + add_header Cache-Control "public, must-revalidate" always; + try_files $uri =404; + } + + location = /miniprogram/assets/route-config.json { + expires 30s; + add_header Cache-Control "public, must-revalidate" always; + try_files $uri =404; + } + + # 字体文件:长缓存 + location ~* \.(ttf|otf|woff|woff2|eot)$ { + expires 30d; + add_header Cache-Control "public, immutable" always; + try_files $uri =404; + } + + # -------------------- Web 静态应用(frontend/dist) -------------------- + + # Vite 构建产物目录:/assets/* + location ^~ /assets/ { + expires 30d; + add_header Cache-Control "public, immutable" always; + try_files /frontend/dist$uri =404; + } + + # 常见入口文件(精确匹配) + location = /index.html { + try_files /frontend/dist/index.html =404; + } + + location = /default.json { + try_files /frontend/dist/default.json =404; + } + + location = /favicon.ico { + try_files /frontend/dist/favicon.ico =404; + } + + location = /favicon.png { + try_files /frontend/dist/favicon.png =404; + } + + location = /favicon.svg { + try_files /frontend/dist/favicon.svg =404; + } + + location = /favicon_new.png { + try_files /frontend/dist/favicon_new.png =404; + } + + # Web SPA 路由回退(刷新任意前端路径时返回 index.html) + location / { + try_files $uri $uri/ /frontend/dist/index.html; + } + + # 禁止访问隐藏文件 + location ~ /\. { + deny all; + access_log off; + log_not_found off; + } +}