mirror of
https://github.com/ctwj/urldb.git
synced 2025-11-25 03:15:04 +08:00
Compare commits
2 Commits
1af7fbd355
...
8a79e7e87b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a79e7e87b | ||
|
|
f67f820ef8 |
@@ -452,9 +452,16 @@ func (h *PublicAPIHandler) recordAPIAccessToDB(ip, userAgent, endpoint, method s
|
|||||||
requestParams interface{}, responseStatus int, responseData interface{},
|
requestParams interface{}, responseStatus int, responseData interface{},
|
||||||
processCount int, errorMessage string, processingTime int64) {
|
processCount int, errorMessage string, processingTime int64) {
|
||||||
|
|
||||||
// 只记录重要的API访问(有错误或处理时间较长的)
|
// 判断是否为关键端点,需要强制记录日志
|
||||||
if errorMessage == "" && processingTime < 1000 && responseStatus < 400 {
|
isKeyEndpoint := strings.Contains(endpoint, "/api/public/resources/batch-add") ||
|
||||||
return // 跳过正常的快速请求
|
strings.Contains(endpoint, "/api/admin/") ||
|
||||||
|
strings.Contains(endpoint, "/telegram/webhook") ||
|
||||||
|
strings.Contains(endpoint, "/api/public/resources/search") ||
|
||||||
|
strings.Contains(endpoint, "/api/public/hot-drama")
|
||||||
|
|
||||||
|
// 只记录重要的API访问(有错误或处理时间较长的)或者是关键端点
|
||||||
|
if errorMessage == "" && processingTime < 1000 && responseStatus < 400 && !isKeyEndpoint {
|
||||||
|
return // 跳过正常的快速请求,但记录关键端点
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换参数为JSON字符串
|
// 转换参数为JSON字符串
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ server {
|
|||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
# API 路由 - 所有 /api/ 开头的请求转发到后端
|
# API 路由 - 所有 /api/ 开头的请求转发到后端
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://backend;
|
proxy_pass http://backend;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
@@ -55,6 +55,23 @@ server {
|
|||||||
proxy_intercept_errors on;
|
proxy_intercept_errors on;
|
||||||
error_page 502 503 504 /50x.html;
|
error_page 502 503 504 /50x.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
location ^~ /uploads/ {
|
||||||
|
proxy_pass http://backend/uploads/;
|
||||||
|
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;
|
||||||
|
|
||||||
|
expires 1y;
|
||||||
|
add_header Cache-Control "public, immutable";
|
||||||
|
|
||||||
|
add_header Access-Control-Allow-Origin "*";
|
||||||
|
add_header Access-Control-Allow-Methods "GET, OPTIONS";
|
||||||
|
add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# 静态文件路由 - 直接转发到前端
|
# 静态文件路由 - 直接转发到前端
|
||||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||||
@@ -69,24 +86,6 @@ server {
|
|||||||
add_header Cache-Control "public, immutable";
|
add_header Cache-Control "public, immutable";
|
||||||
}
|
}
|
||||||
|
|
||||||
# 上传文件路由 - 直接访问后端的上传目录
|
|
||||||
location /uploads/ {
|
|
||||||
proxy_pass http://backend;
|
|
||||||
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;
|
|
||||||
|
|
||||||
# 缓存设置
|
|
||||||
expires 1y;
|
|
||||||
add_header Cache-Control "public, immutable";
|
|
||||||
|
|
||||||
# 允许跨域访问
|
|
||||||
add_header Access-Control-Allow-Origin "*";
|
|
||||||
add_header Access-Control-Allow-Methods "GET, OPTIONS";
|
|
||||||
add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept";
|
|
||||||
}
|
|
||||||
|
|
||||||
# 微信公众号验证文件路由 - 根目录的TXT文件直接访问后端uploads目录
|
# 微信公众号验证文件路由 - 根目录的TXT文件直接访问后端uploads目录
|
||||||
location ~ ^/[^/]+\.txt$ {
|
location ~ ^/[^/]+\.txt$ {
|
||||||
# 检查文件是否存在于uploads目录
|
# 检查文件是否存在于uploads目录
|
||||||
|
|||||||
Reference in New Issue
Block a user