mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 03:07:20 +08:00
fix: 优化php配置
This commit is contained in:
@@ -1084,7 +1084,7 @@ func (r *websiteRepo) reloadWebServer() error {
|
||||
return err
|
||||
}
|
||||
case "apache":
|
||||
if err = systemctl.Reload("httpd"); err != nil {
|
||||
if err = systemctl.Reload("apache"); err != nil {
|
||||
_, err = shell.Execf("apachectl configtest")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -641,14 +641,14 @@ func (v *PHPVhost) PHP() uint {
|
||||
}
|
||||
|
||||
// 从配置内容中提取版本号
|
||||
// 格式: Include /opt/ace/server/apache/conf/extra/enable-php-85.conf
|
||||
idx := strings.Index(content, "enable-php-")
|
||||
// 格式: proxy:unix:/tmp/php-cgi-84.sock|fcgi://localhost/
|
||||
idx := strings.Index(content, "php-cgi-")
|
||||
if idx == -1 {
|
||||
return 0
|
||||
}
|
||||
|
||||
var result uint
|
||||
_, err := fmt.Sscanf(content[idx:], "enable-php-%d.conf", &result)
|
||||
_, err := fmt.Sscanf(content[idx:], "php-cgi-%d.sock", &result)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
@@ -660,9 +660,13 @@ func (v *PHPVhost) SetPHP(version uint) error {
|
||||
return v.RemoveConfig("010-php.conf", "site")
|
||||
}
|
||||
|
||||
// 生成 PHP-FPM 配置,直接 Include Apache 的 PHP-FPM 配置文件
|
||||
// 配置文件路径: /opt/ace/server/apache/conf/extra/enable-php-85.conf
|
||||
content := fmt.Sprintf("Include conf/extra/enable-php-%d.conf\n", version)
|
||||
// 生成 PHP-FPM 配置
|
||||
// sock 路径格式: unix:/tmp/php-cgi-84.sock
|
||||
content := fmt.Sprintf(`# Auto-generated by AcePanel. DO NOT EDIT MANUALLY!
|
||||
<FilesMatch \.php$>
|
||||
SetHandler "proxy:unix:/tmp/php-cgi-%d.sock|fcgi://localhost/"
|
||||
</FilesMatch>
|
||||
`, version)
|
||||
|
||||
return v.SetConfig("010-php.conf", "site", content)
|
||||
}
|
||||
|
||||
@@ -324,9 +324,8 @@ func (s *VhostTestSuite) TestDirectoryBlock() {
|
||||
func (s *VhostTestSuite) TestPHPFilesMatchBlock() {
|
||||
s.NoError(s.vhost.SetPHP(84))
|
||||
|
||||
// PHP 配置现在在独立文件中
|
||||
content := s.vhost.Config("010-php.conf", "site")
|
||||
s.Contains(content, "Include conf/extra/enable-php-84.conf")
|
||||
s.Contains(content, "proxy:unix:/tmp/php-cgi-84.sock|fcgi://localhost/")
|
||||
}
|
||||
|
||||
func (s *VhostTestSuite) TestDefaultVhostConfIncludesServerD() {
|
||||
|
||||
@@ -748,8 +748,15 @@ func (v *PHPVhost) PHP() uint {
|
||||
return 0
|
||||
}
|
||||
|
||||
// 从配置内容中提取版本号
|
||||
// 格式: fastcgi_pass unix:/tmp/php-cgi-84.sock;
|
||||
idx := strings.Index(content, "php-cgi-")
|
||||
if idx == -1 {
|
||||
return 0
|
||||
}
|
||||
|
||||
var result uint
|
||||
_, err := fmt.Sscanf(content, "include enable-php-%d.conf;", &result)
|
||||
_, err := fmt.Sscanf(content[idx:], "php-cgi-%d.sock", &result)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
@@ -760,7 +767,20 @@ func (v *PHPVhost) SetPHP(version uint) error {
|
||||
if version == 0 {
|
||||
return v.RemoveConfig("010-php.conf", "site")
|
||||
}
|
||||
return v.SetConfig("010-php.conf", "site", fmt.Sprintf("include enable-php-%d.conf;\n", version))
|
||||
|
||||
// 生成 PHP-FPM 配置
|
||||
// sock 路径格式: unix:/tmp/php-cgi-84.sock
|
||||
content := fmt.Sprintf(`# Auto-generated by AcePanel. DO NOT EDIT MANUALLY!
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_pass unix:/tmp/php-cgi-%d.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi.conf;
|
||||
include pathinfo.conf;
|
||||
}
|
||||
`, version)
|
||||
|
||||
return v.SetConfig("010-php.conf", "site", content)
|
||||
}
|
||||
|
||||
// ========== ProxyVhost ==========
|
||||
|
||||
Reference in New Issue
Block a user