feat: 优化非80端口网站开启 https 端口配置 (#5443)

Refs https://github.com/1Panel-dev/1Panel/issues/5364
This commit is contained in:
zhengkunwang 2024-06-13 16:14:37 +08:00 committed by GitHub
parent 01588ed9b5
commit 3b7f8c2724
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -563,6 +563,16 @@ func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.We
if err != nil {
return nil
}
domains, err := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(website.ID))
if err != nil {
return nil
}
noDefaultPort := true
for _, domain := range domains {
if domain.Port == 80 {
noDefaultPort = false
}
}
config := nginxFull.SiteConfig.Config
server := config.FindServers()[0]
@ -582,13 +592,17 @@ func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.We
server.RemoveListenByBind(httpPortIPV6)
server.RemoveDirective("if", []string{"($scheme"})
case constant.HTTPToHTTPS:
server.UpdateListen(httpPort, website.DefaultServer)
if !noDefaultPort {
server.UpdateListen(httpPort, website.DefaultServer)
}
if website.IPV6 {
server.UpdateListen(httpPortIPV6, website.DefaultServer)
}
server.AddHTTP2HTTPS()
case constant.HTTPAlso:
server.UpdateListen(httpPort, website.DefaultServer)
if !noDefaultPort {
server.UpdateListen(httpPort, website.DefaultServer)
}
server.RemoveDirective("if", []string{"($scheme"})
if website.IPV6 {
server.UpdateListen(httpPortIPV6, website.DefaultServer)