mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-24 19:19:15 +08:00
feat: 优化网站 IPV6 设置 (#1732)
Refs https://github.com/1Panel-dev/1Panel/issues/1404
This commit is contained in:
parent
c14e192bee
commit
34e8d88a53
@ -342,6 +342,11 @@ func (w WebsiteService) UpdateWebsite(req request.WebsiteUpdate) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if website.IPV6 != req.IPV6 {
|
||||
if err := changeIPV6(website, req.IPV6); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
website.PrimaryDomain = req.PrimaryDomain
|
||||
website.WebsiteGroupID = req.WebsiteGroupID
|
||||
website.Remark = req.Remark
|
||||
|
@ -576,6 +576,44 @@ func opWebsite(website *model.Website, operate string) error {
|
||||
return nginxCheckAndReload(nginxInstall.SiteConfig.OldContent, config.FilePath, nginxInstall.Install.ContainerName)
|
||||
}
|
||||
|
||||
func changeIPV6(website model.Website, enable bool) error {
|
||||
nginxFull, err := getNginxFull(&website)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
config := nginxFull.SiteConfig.Config
|
||||
server := config.FindServers()[0]
|
||||
listens := server.Listens
|
||||
if enable {
|
||||
for _, listen := range listens {
|
||||
if strings.HasPrefix(listen.Bind, "[::]:") {
|
||||
continue
|
||||
}
|
||||
exist := false
|
||||
ipv6Bind := fmt.Sprintf("[::]:%s", listen.Bind)
|
||||
for _, li := range listens {
|
||||
if li.Bind == ipv6Bind {
|
||||
exist = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exist {
|
||||
server.UpdateListen(ipv6Bind, false, listen.GetParameters()[1:]...)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, listen := range listens {
|
||||
if strings.HasPrefix(listen.Bind, "[::]:") {
|
||||
server.RemoveListenByBind(listen.Bind)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
|
||||
return err
|
||||
}
|
||||
return nginxCheckAndReload(nginxFull.SiteConfig.OldContent, config.FilePath, nginxFull.Install.ContainerName)
|
||||
}
|
||||
|
||||
func checkIsLinkApp(website model.Website) bool {
|
||||
if website.Type == constant.Deployment {
|
||||
return true
|
||||
|
@ -315,7 +315,7 @@ func (s *Server) UpdateDirectiveBySecondKey(name string, key string, directive D
|
||||
func (s *Server) RemoveListenByBind(bind string) {
|
||||
var listens []*ServerListen
|
||||
for _, listen := range s.Listens {
|
||||
if listen.Bind != bind || len(listen.Parameters) > 0 {
|
||||
if listen.Bind != bind {
|
||||
listens = append(listens, listen)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user