diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ece206..b06b04e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # 更新日志 +24w18e +--- +- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 +- CHANGE: 引入H2C协议支持,支持无加密HTTP/2请求 +- ADD: 尝试在核心程序内加入静态页面支持 +- CHANGE: 优化日志记录 +- CHANGE: 去除部分无用/重复配置 + 24w18d --- - PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 diff --git a/DEV-VERSION b/DEV-VERSION index fd72f28..164704b 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w18d \ No newline at end of file +24w18e \ No newline at end of file diff --git a/README.md b/README.md index da48636..d7fe435 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,10 @@ host = "127.0.0.1" # 监听地址 port = 8080 # 监听端口 sizeLimit = 131072000 # 125MB +[page] +enabled = true # 是否开启内置静态页面 +staticPath = "/data/www" # 静态页面文件路径 + [log] logFilePath = "/data/ghproxy/log/ghproxy.log" # 日志文件路径 maxLogSize = 5 # MB 日志文件最大大小 diff --git a/SECURITY.MD b/SECURITY.MD index aef0700..2bd9114 100644 --- a/SECURITY.MD +++ b/SECURITY.MD @@ -17,6 +17,7 @@ 使用本项目,请遵循 **[WSL (WJQSERVER-STUDIO LICENSE)](https://wjqserver-studio.github.io/LICENSE/LICENSE.html)** 协议。 本项目所有文件均受到 WSL (WJQSERVER-STUDIO LICENSE) 协议保护,任何人不得在任何情况下以非 WSL (WJQSERVER-STUDIO LICENSE) 协议内规定的方式使用,复制,修改,编译,发布,分发,再许可,或者出售本项目的任何部分。 + ## 报告漏洞 如果您发现本项目存在安全漏洞,请通过发送ISSUES或尝试联系项目维护者来报告。请在您的报告中包含以下信息: diff --git a/caddyfile/dev/Caddyfile b/caddyfile/dev/Caddyfile index 0b2318e..aba4935 100644 --- a/caddyfile/dev/Caddyfile +++ b/caddyfile/dev/Caddyfile @@ -68,7 +68,7 @@ :80 { reverse_proxy { - to 127.0.0.1:8080 + to h2c://127.0.0.1:8080 import header_realip } import log ghproxy @@ -76,8 +76,6 @@ import error_page import encode import rate_limit 60 - header Age 10 - header Cache-Control "max-age=300" route / { root /data/www file_server diff --git a/config/config.go b/config/config.go index 85fcc22..59e6b1d 100644 --- a/config/config.go +++ b/config/config.go @@ -6,6 +6,7 @@ import ( type Config struct { Server ServerConfig + Page PageConfig Log LogConfig CORS CORSConfig Auth AuthConfig @@ -19,6 +20,11 @@ type ServerConfig struct { SizeLimit int `toml:"sizeLimit"` } +type PageConfig struct { + Enabled bool `toml:"enabled"` + StaticDir string `toml:"staticDir"` +} + type LogConfig struct { LogFilePath string `toml:"logFilePath"` MaxLogSize int `toml:"maxLogSize"` diff --git a/config/config.toml b/config/config.toml index 1047984..974c8d4 100644 --- a/config/config.toml +++ b/config/config.toml @@ -3,6 +3,10 @@ host = "127.0.0.1" port = 8080 sizeLimit = 131072000 # 125MB +[page] +enabled = true +staticDir = "/data/www" + [log] logFilePath = "/data/ghproxy/log/ghproxy.log" maxLogSize = 5 # MB diff --git a/deploy/config.toml b/deploy/config.toml index 3b74289..11a64b6 100644 --- a/deploy/config.toml +++ b/deploy/config.toml @@ -3,6 +3,10 @@ host = "127.0.0.1" port = 8080 sizeLimit = 131072000 # 125MB +[page] +enabled = true +staticDir = "/root/data/ghproxy/pages" + [log] logFilePath = "/root/data/ghproxy/log/ghproxy.log" maxLogSize = 5 # MB diff --git a/deploy/install-dev.sh b/deploy/install-dev.sh index 3197c8b..15b68d7 100644 --- a/deploy/install-dev.sh +++ b/deploy/install-dev.sh @@ -53,6 +53,7 @@ fi mkdir -p /root/data/ghproxy mkdir -p /root/data/ghproxy/config mkdir -p /root/data/ghproxy/log +mkdir -p /root/data/ghproxy/pages # 获取最新版本号 VERSION=$(curl -s https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION) @@ -62,6 +63,11 @@ wget -O /root/data/ghproxy/VERSION https://raw.githubusercontent.com/WJQSERVER-S wget -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH chmod +x /root/data/ghproxy/ghproxy +# 下载pages +wget -O /root/data/ghproxy/pages/index.html https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/index.html +wget -O /root/data/ghproxy/pages/favicon.ico https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/favicon.ico + + # 下载配置文件 if [ -f /root/data/ghproxy/config/config.toml ]; then echo "配置文件已存在, 跳过下载" diff --git a/main.go b/main.go index 0c6e62d..9c4a8ca 100644 --- a/main.go +++ b/main.go @@ -75,13 +75,23 @@ func init() { gin.SetMode(gin.ReleaseMode) router = gin.Default() + router.UseH2C = true setupApi(cfg, router) - router.GET("/", func(c *gin.Context) { - c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.") - LogWarning("Forbidden: IP:%s UA:%s METHOD:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method) - }) + if cfg.Page.Enabled { + indexPagePath := fmt.Sprintf("%s/index.html", cfg.Page.StaticDir) + faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Page.StaticDir) + // 静态index页 + router.StaticFile("/", indexPagePath) + // 静态favicon.ico + router.StaticFile("/favicon.ico", faviconPath) + } else if !cfg.Page.Enabled { + router.GET("/", func(c *gin.Context) { + c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.") + LogWarning("Forbidden: IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto) + }) + } // 未匹配路由处理 router.NoRoute(func(c *gin.Context) { diff --git a/proxy/proxy.go b/proxy/proxy.go index 4614a13..9593dbd 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -117,7 +117,8 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) { method := c.Request.Method - logInfo("%s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent")) + // 记录日志 IP 地址、请求方法、请求 URL、请求头 User-Agent 、HTTP版本 + logInfo("%s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto) client := createHTTPClient(mode)