2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 10:17:17 +08:00

feat: PHP环境支持管理

This commit is contained in:
2026-01-08 01:43:21 +08:00
parent 45616b4ab3
commit 7940b50a72
23 changed files with 93 additions and 272 deletions

View File

@@ -147,7 +147,7 @@ func (v *baseVhost) Listen() []types.Listen {
// Apache 的监听配置通常在 VirtualHost 的参数中
// 例如: <VirtualHost *:80> 或 <VirtualHost 192.168.1.1:443>
for _, arg := range v.vhost.Args {
listen := types.Listen{Address: arg}
listen := types.Listen{Address: arg, Args: []string{}}
result = append(result, listen)
}

View File

@@ -121,7 +121,6 @@ func parseProxyFile(filePath string) (*types.Proxy, error) {
if rm := resolverPattern.FindStringSubmatch(blockContent); rm != nil {
parts := strings.Fields(rm[1])
proxy.Resolver = parts
proxy.AutoRefresh = true // 有 resolver 通常意味着需要自动刷新
}
// 解析 resolver_timeout
@@ -218,19 +217,16 @@ func generateProxyConfig(proxy types.Proxy) string {
sb.WriteString(fmt.Sprintf("location %s {\n", location))
// resolver 配置(如果启用自动刷新)
if proxy.AutoRefresh && len(proxy.Resolver) > 0 {
// resolver 配置
if len(proxy.Resolver) > 0 {
sb.WriteString(fmt.Sprintf(" resolver %s;\n", strings.Join(proxy.Resolver, " ")))
if proxy.ResolverTimeout > 0 {
sb.WriteString(fmt.Sprintf(" resolver_timeout %ds;\n", int(proxy.ResolverTimeout.Seconds())))
}
// 使用变量实现动态解析
sb.WriteString(fmt.Sprintf(" set $backend \"%s\";\n", proxy.Pass))
sb.WriteString(" proxy_pass $backend;\n")
} else {
sb.WriteString(fmt.Sprintf(" proxy_pass %s;\n", proxy.Pass))
}
sb.WriteString(fmt.Sprintf(" proxy_pass %s;\n", proxy.Pass))
// Host 头
if proxy.Host != "" {
sb.WriteString(fmt.Sprintf(" proxy_set_header Host \"%s\";\n", proxy.Host))

View File

@@ -158,7 +158,7 @@ func (v *baseVhost) Listen() []types.Listen {
var result []types.Listen
for _, dir := range directives {
l := v.parser.parameters2Slices(dir.GetParameters())
listen := types.Listen{Address: l[0]}
listen := types.Listen{Address: l[0], Args: []string{}}
for i := 1; i < len(l); i++ {
listen.Args = append(listen.Args, l[i])
}

View File

@@ -5,7 +5,6 @@ import "time"
// Proxy 反向代理配置
type Proxy struct {
Location string `form:"location" json:"location" validate:"required"` // 匹配路径,如: "/", "/api", "~ ^/api/v[0-9]+/"
AutoRefresh bool `form:"auto_refresh" json:"auto_refresh"` // 是否自动刷新解析
Pass string `form:"pass" json:"pass" validate:"required"` // 代理地址,如: "http://example.com", "http://backend"
Host string `form:"host" json:"host"` // 代理 Host如: "example.com"
SNI string `form:"sni" json:"sni"` // 代理 SNI如: "example.com"
@@ -18,7 +17,7 @@ type Proxy struct {
// Upstream 上游服务器配置
type Upstream struct {
Servers map[string]string `form:"servers" json:"servers" validate:"required"` // 上游服务器及权重,如: map["server1"] = "weight=5"
Servers map[string]string `form:"servers" json:"servers" validate:"required"` // 上游服务器及配置,如: map["server1"] = "weight=5 resolve"
Algo string `form:"algo" json:"algo"` // 负载均衡算法,如: "least_conn", "ip_hash"
Keepalive int `form:"keepalive" json:"keepalive"` // 保持连接数,如: 32
}

View File

@@ -8,7 +8,6 @@ import (
"github.com/acepanel/panel/pkg/webserver/types"
)
// NewStaticVhost 创建纯静态虚拟主机实例
func NewStaticVhost(serverType Type, configDir string) (types.StaticVhost, error) {
switch serverType {
case TypeNginx:
@@ -20,7 +19,6 @@ func NewStaticVhost(serverType Type, configDir string) (types.StaticVhost, error
}
}
// NewPHPVhost 创建 PHP 虚拟主机实例
func NewPHPVhost(serverType Type, configDir string) (types.PHPVhost, error) {
switch serverType {
case TypeNginx:
@@ -32,7 +30,6 @@ func NewPHPVhost(serverType Type, configDir string) (types.PHPVhost, error) {
}
}
// NewProxyVhost 创建反向代理虚拟主机实例
func NewProxyVhost(serverType Type, configDir string) (types.ProxyVhost, error) {
switch serverType {
case TypeNginx: