update at 2026-02-08 18:28:39
This commit is contained in:
104
fonts.conf
Normal file
104
fonts.conf
Normal file
@@ -0,0 +1,104 @@
|
||||
# Font2SVG - Nginx 配置(fonts.biboer.cn)
|
||||
# 用途:为微信小程序提供 fonts.json 与字体文件静态托管
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name fonts.biboer.cn;
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name fonts.biboer.cn;
|
||||
|
||||
# Certbot 证书
|
||||
ssl_certificate /etc/letsencrypt/live/fonts.biboer.cn/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/fonts.biboer.cn/privkey.pem;
|
||||
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||
|
||||
# 静态资源根目录(需包含 fonts.json 与 fonts/ 目录)
|
||||
root /home/gavin/font2svg;
|
||||
index fonts.json;
|
||||
|
||||
access_log /var/log/nginx/font2svg_access.log;
|
||||
error_log /var/log/nginx/font2svg_error.log;
|
||||
|
||||
server_tokens off;
|
||||
|
||||
# 小程序跨域访问
|
||||
add_header Access-Control-Allow-Origin "*" always;
|
||||
add_header Access-Control-Allow-Methods "GET,HEAD,OPTIONS" always;
|
||||
add_header Access-Control-Allow-Headers "Origin,Range,Accept,Content-Type" 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 服务)
|
||||
location /api/ {
|
||||
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;
|
||||
}
|
||||
|
||||
# fonts.json:短缓存,便于更新
|
||||
location = /fonts.json {
|
||||
expires 1h;
|
||||
add_header Cache-Control "public, must-revalidate";
|
||||
add_header Access-Control-Allow-Origin "*" always;
|
||||
add_header Access-Control-Allow-Methods "GET,HEAD,OPTIONS" always;
|
||||
add_header Access-Control-Allow-Headers "Origin,Range,Accept,Content-Type" always;
|
||||
add_header Access-Control-Expose-Headers "Content-Length,Content-Range" always;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# 字体文件:长缓存
|
||||
location ~* \.(ttf|otf|woff|woff2|eot)$ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
add_header Access-Control-Allow-Origin "*" always;
|
||||
add_header Access-Control-Allow-Methods "GET,HEAD,OPTIONS" always;
|
||||
add_header Access-Control-Allow-Headers "Origin,Range,Accept,Content-Type" always;
|
||||
add_header Access-Control-Expose-Headers "Content-Length,Content-Range" always;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# 默认仅允许静态文件
|
||||
location / {
|
||||
# 处理预检请求(if 在 location 内合法)
|
||||
if ($request_method = OPTIONS) {
|
||||
add_header Access-Control-Allow-Origin "*";
|
||||
add_header Access-Control-Allow-Methods "GET,HEAD,OPTIONS";
|
||||
add_header Access-Control-Allow-Headers "Origin,Range,Accept,Content-Type";
|
||||
add_header Access-Control-Max-Age 1728000;
|
||||
add_header Content-Length 0;
|
||||
add_header Content-Type "text/plain; charset=utf-8";
|
||||
return 204;
|
||||
}
|
||||
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# 禁止访问隐藏文件
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user