This commit is contained in:
WJQSERVER 2024-10-20 17:39:27 +08:00
parent c50f23c399
commit e5d941414e
11 changed files with 51 additions and 9 deletions

View file

@ -1,5 +1,13 @@
# 更新日志 # 更新日志
24w18e
---
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用
- CHANGE: 引入H2C协议支持,支持无加密HTTP/2请求
- ADD: 尝试在核心程序内加入静态页面支持
- CHANGE: 优化日志记录
- CHANGE: 去除部分无用/重复配置
24w18d 24w18d
--- ---
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 - PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用

View file

@ -1 +1 @@
24w18d 24w18e

View file

@ -81,6 +81,10 @@ host = "127.0.0.1" # 监听地址
port = 8080 # 监听端口 port = 8080 # 监听端口
sizeLimit = 131072000 # 125MB sizeLimit = 131072000 # 125MB
[page]
enabled = true # 是否开启内置静态页面
staticPath = "/data/www" # 静态页面文件路径
[log] [log]
logFilePath = "/data/ghproxy/log/ghproxy.log" # 日志文件路径 logFilePath = "/data/ghproxy/log/ghproxy.log" # 日志文件路径
maxLogSize = 5 # MB 日志文件最大大小 maxLogSize = 5 # MB 日志文件最大大小

View file

@ -17,6 +17,7 @@
使用本项目,请遵循 **[WSL (WJQSERVER-STUDIO LICENSE)](https://wjqserver-studio.github.io/LICENSE/LICENSE.html)** 协议。 使用本项目,请遵循 **[WSL (WJQSERVER-STUDIO LICENSE)](https://wjqserver-studio.github.io/LICENSE/LICENSE.html)** 协议。
本项目所有文件均受到 WSL (WJQSERVER-STUDIO LICENSE) 协议保护,任何人不得在任何情况下以非 WSL (WJQSERVER-STUDIO LICENSE) 协议内规定的方式使用,复制,修改,编译,发布,分发,再许可,或者出售本项目的任何部分。 本项目所有文件均受到 WSL (WJQSERVER-STUDIO LICENSE) 协议保护,任何人不得在任何情况下以非 WSL (WJQSERVER-STUDIO LICENSE) 协议内规定的方式使用,复制,修改,编译,发布,分发,再许可,或者出售本项目的任何部分。
## 报告漏洞 ## 报告漏洞
如果您发现本项目存在安全漏洞,请通过发送ISSUES或尝试联系项目维护者来报告。请在您的报告中包含以下信息: 如果您发现本项目存在安全漏洞,请通过发送ISSUES或尝试联系项目维护者来报告。请在您的报告中包含以下信息:

View file

@ -68,7 +68,7 @@
:80 { :80 {
reverse_proxy { reverse_proxy {
to 127.0.0.1:8080 to h2c://127.0.0.1:8080
import header_realip import header_realip
} }
import log ghproxy import log ghproxy
@ -76,8 +76,6 @@
import error_page import error_page
import encode import encode
import rate_limit 60 import rate_limit 60
header Age 10
header Cache-Control "max-age=300"
route / { route / {
root /data/www root /data/www
file_server file_server

View file

@ -6,6 +6,7 @@ import (
type Config struct { type Config struct {
Server ServerConfig Server ServerConfig
Page PageConfig
Log LogConfig Log LogConfig
CORS CORSConfig CORS CORSConfig
Auth AuthConfig Auth AuthConfig
@ -19,6 +20,11 @@ type ServerConfig struct {
SizeLimit int `toml:"sizeLimit"` SizeLimit int `toml:"sizeLimit"`
} }
type PageConfig struct {
Enabled bool `toml:"enabled"`
StaticDir string `toml:"staticDir"`
}
type LogConfig struct { type LogConfig struct {
LogFilePath string `toml:"logFilePath"` LogFilePath string `toml:"logFilePath"`
MaxLogSize int `toml:"maxLogSize"` MaxLogSize int `toml:"maxLogSize"`

View file

@ -3,6 +3,10 @@ host = "127.0.0.1"
port = 8080 port = 8080
sizeLimit = 131072000 # 125MB sizeLimit = 131072000 # 125MB
[page]
enabled = true
staticDir = "/data/www"
[log] [log]
logFilePath = "/data/ghproxy/log/ghproxy.log" logFilePath = "/data/ghproxy/log/ghproxy.log"
maxLogSize = 5 # MB maxLogSize = 5 # MB

View file

@ -3,6 +3,10 @@ host = "127.0.0.1"
port = 8080 port = 8080
sizeLimit = 131072000 # 125MB sizeLimit = 131072000 # 125MB
[page]
enabled = true
staticDir = "/root/data/ghproxy/pages"
[log] [log]
logFilePath = "/root/data/ghproxy/log/ghproxy.log" logFilePath = "/root/data/ghproxy/log/ghproxy.log"
maxLogSize = 5 # MB maxLogSize = 5 # MB

View file

@ -53,6 +53,7 @@ fi
mkdir -p /root/data/ghproxy mkdir -p /root/data/ghproxy
mkdir -p /root/data/ghproxy/config mkdir -p /root/data/ghproxy/config
mkdir -p /root/data/ghproxy/log 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) 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 wget -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH
chmod +x /root/data/ghproxy/ghproxy 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 if [ -f /root/data/ghproxy/config/config.toml ]; then
echo "配置文件已存在, 跳过下载" echo "配置文件已存在, 跳过下载"

12
main.go
View file

@ -75,13 +75,23 @@ func init() {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
router = gin.Default() router = gin.Default()
router.UseH2C = true
setupApi(cfg, router) setupApi(cfg, router)
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) { router.GET("/", func(c *gin.Context) {
c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.") 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) 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) { router.NoRoute(func(c *gin.Context) {

View file

@ -117,7 +117,8 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) { func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
method := c.Request.Method 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) client := createHTTPClient(mode)