From 5d41fa979e2835b0fb5e35c5e09b7a08219d9d44 Mon Sep 17 00:00:00 2001 From: NewName Date: Sun, 18 May 2025 14:45:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0CF-CDN=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 47 +++++++++++++++++++++++++++++++++++++++ ghproxy/main.go | 2 +- ghproxy/skopeo_service.go | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 25ad018..3f4b5ab 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,53 @@ docker run -d \ ghcr.io/sky22333/hub-proxy ``` +--- +--- + + +
+ CF-CDN获取用户真实IP + + +- 替换`Caddyfile`配置 + +``` +hub.{$DOMAIN} { + reverse_proxy * ghproxy:5000 { + header_up X-Real-IP {http.request.header.CF-Connecting-IP} + header_up X-Forwarded-For {http.request.header.CF-Connecting-IP} + header_up X-Forwarded-Proto {http.request.scheme} + header_up CF-IPCountry {http.request.header.CF-IPCountry} + } +} + +docker.{$DOMAIN} { + @v2_manifest_blob path_regexp v2_rewrite ^/v2/([^/]+)/(manifests|blobs)/(.*)$ + handle @v2_manifest_blob { + rewrite * /v2/library/{re.v2_rewrite.1}/{re.v2_rewrite.2}/{re.v2_rewrite.3} + } + + reverse_proxy * docker:5000 { + header_up X-Real-IP {http.request.header.CF-Connecting-IP} + header_up X-Forwarded-For {http.request.header.CF-Connecting-IP} + header_up X-Forwarded-Proto {http.request.scheme} + header_up CF-IPCountry {http.request.header.CF-IPCountry} + } +} + +ghcr.{$DOMAIN} { + reverse_proxy * ghcr:5000 { + header_up X-Real-IP {http.request.header.CF-Connecting-IP} + header_up X-Forwarded-For {http.request.header.CF-Connecting-IP} + header_up X-Forwarded-Proto {http.request.scheme} + header_up CF-IPCountry {http.request.header.CF-IPCountry} + } +} +``` + +
+ + --- --- diff --git a/ghproxy/main.go b/ghproxy/main.go index effcb7e..e428c41 100644 --- a/ghproxy/main.go +++ b/ghproxy/main.go @@ -16,7 +16,7 @@ import ( ) const ( - sizeLimit = 1024 * 1024 * 1024 * 10 // 允许的文件大小,默认10GB + sizeLimit = 1024 * 1024 * 1024 * 2 // 允许的文件大小,默认2GB host = "0.0.0.0" // 监听地址 port = 5000 // 监听端口 ) diff --git a/ghproxy/skopeo_service.go b/ghproxy/skopeo_service.go index 1da0a8f..1e7c0d9 100644 --- a/ghproxy/skopeo_service.go +++ b/ghproxy/skopeo_service.go @@ -1030,7 +1030,7 @@ func cleanupTempFiles() { } // 如果总大小超过10GB,清理所有文件,防止恶意下载导致磁盘爆满 - if totalSize > 10*1024*1024*1024 { // 15GB + if totalSize > 10*1024*1024*1024 { fmt.Printf("临时文件总大小超过10GB (当前: %.2f GB),清理所有文件\n", float64(totalSize)/(1024*1024*1024)) cleanAll() } else {