diff --git a/agent/app/dto/request/website.go b/agent/app/dto/request/website.go
index b713dcc2d..b85d53515 100644
--- a/agent/app/dto/request/website.go
+++ b/agent/app/dto/request/website.go
@@ -145,6 +145,7 @@ type WebsiteHTTPSOp struct {
SSLProtocol []string `json:"SSLProtocol"`
Algorithm string `json:"algorithm"`
Hsts bool `json:"hsts"`
+ HttpsPort int `json:"httpsPort"`
}
type WebsiteNginxUpdate struct {
diff --git a/agent/app/dto/response/website.go b/agent/app/dto/response/website.go
index 4aaff56b6..a61a89462 100644
--- a/agent/app/dto/response/website.go
+++ b/agent/app/dto/response/website.go
@@ -59,6 +59,7 @@ type WebsiteHTTPS struct {
SSLProtocol []string `json:"SSLProtocol"`
Algorithm string `json:"algorithm"`
Hsts bool `json:"hsts"`
+ HttpsPort int `json:"httpsPort"`
}
type WebsiteLog struct {
diff --git a/agent/app/model/website.go b/agent/app/model/website.go
index 15748739c..1b49bb2ac 100644
--- a/agent/app/model/website.go
+++ b/agent/app/model/website.go
@@ -28,6 +28,8 @@ type Website struct {
AppInstallID uint `gorm:"type:integer" json:"appInstallId"`
FtpID uint `gorm:"type:integer" json:"ftpId"`
+ HttpsPort int `json:"httpsPort"`
+
User string `gorm:"type:varchar;" json:"user"`
Group string `gorm:"type:varchar;" json:"group"`
diff --git a/agent/app/service/website.go b/agent/app/service/website.go
index 705f8544a..e3bc9fb2e 100644
--- a/agent/app/service/website.go
+++ b/agent/app/service/website.go
@@ -225,6 +225,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
return err
}
defaultHttpPort := nginxInstall.HttpPort
+ defaultHttpsPort := nginxInstall.HttpsPort
var (
otherDomains []model.WebsiteDomain
@@ -239,6 +240,9 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
return err
}
domains = append(domains, otherDomains...)
+ if len(domains) == 1 && domains[0].Port != defaultHttpPort {
+ defaultHttpsPort = domains[0].Port
+ }
defaultDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate)
website := &model.Website{
@@ -255,6 +259,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
AccessLog: true,
ErrorLog: true,
IPV6: create.IPV6,
+ HttpsPort: defaultHttpsPort,
}
var (
@@ -459,8 +464,9 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
SSLProtocol: []string{"TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1"},
Algorithm: "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED",
Hsts: true,
+ HttpsPort: website.HttpsPort,
}
- if err = applySSL(*website, *websiteModel, appSSLReq); err != nil {
+ if err = applySSL(website, *websiteModel, appSSLReq); err != nil {
return err
}
if err = websiteRepo.Save(context.Background(), website); err != nil {
@@ -863,6 +869,7 @@ func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS,
return response.WebsiteHTTPS{}, err
}
var res response.WebsiteHTTPS
+ res.HttpsPort = website.HttpsPort
if website.WebsiteSSLID == 0 {
res.Enable = false
return res, nil
@@ -918,9 +925,12 @@ func (w WebsiteService) OpWebsiteHTTPS(ctx context.Context, req request.WebsiteH
if !req.Enable {
website.Protocol = constant.ProtocolHTTP
website.WebsiteSSLID = 0
- _, httpsPort, err := getAppInstallPort(constant.AppOpenresty)
- if err != nil {
- return nil, err
+ httpsPort := website.HttpsPort
+ if httpsPort == 0 {
+ _, httpsPort, err = getAppInstallPort(constant.AppOpenresty)
+ if err != nil {
+ return nil, err
+ }
}
httpsPortStr := strconv.Itoa(httpsPort)
if err := deleteListenAndServerName(website, []string{httpsPortStr, "[::]:" + httpsPortStr}, []string{}); err != nil {
@@ -1025,7 +1035,7 @@ func (w WebsiteService) OpWebsiteHTTPS(ctx context.Context, req request.WebsiteH
}
website.Protocol = constant.ProtocolHTTPS
- if err := applySSL(website, websiteSSL, req); err != nil {
+ if err := applySSL(&website, websiteSSL, req); err != nil {
return nil, err
}
website.HttpConfig = req.HttpConfig
diff --git a/agent/app/service/website_utils.go b/agent/app/service/website_utils.go
index d3732d44b..83bf0c245 100644
--- a/agent/app/service/website_utils.go
+++ b/agent/app/service/website_utils.go
@@ -568,8 +568,8 @@ func createPemFile(website model.Website, websiteSSL model.WebsiteSSL) error {
return nil
}
-func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.WebsiteHTTPSOp) error {
- nginxFull, err := getNginxFull(&website)
+func applySSL(website *model.Website, websiteSSL model.WebsiteSSL, req request.WebsiteHTTPSOp) error {
+ nginxFull, err := getNginxFull(website)
if err != nil {
return nil
}
@@ -587,11 +587,15 @@ func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.We
server := config.FindServers()[0]
httpPort := strconv.Itoa(nginxFull.Install.HttpPort)
- httpsPort := strconv.Itoa(nginxFull.Install.HttpsPort)
+ httpsPort := nginxFull.Install.HttpsPort
+ if req.HttpsPort > 0 {
+ httpsPort = req.HttpsPort
+ }
+ website.HttpsPort = httpsPort
httpPortIPV6 := "[::]:" + httpPort
- httpsPortIPV6 := "[::]:" + httpsPort
+ httpsPortIPV6 := "[::]:" + strconv.Itoa(httpsPort)
- server.UpdateListen(httpsPort, website.DefaultServer, "ssl", "http2")
+ server.UpdateListen(strconv.Itoa(httpsPort), website.DefaultServer, "ssl", "http2")
if website.IPV6 {
server.UpdateListen(httpsPortIPV6, website.DefaultServer, "ssl", "http2")
}
@@ -626,7 +630,7 @@ func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.We
if err := nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
return err
}
- if err := createPemFile(website, websiteSSL); err != nil {
+ if err := createPemFile(*website, websiteSSL); err != nil {
return err
}
nginxParams := getNginxParamsFromStaticFile(dto.SSL, []dto.NginxParam{})
@@ -651,7 +655,7 @@ func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.We
})
}
- if err := updateNginxConfig(constant.NginxScopeServer, nginxParams, &website); err != nil {
+ if err := updateNginxConfig(constant.NginxScopeServer, nginxParams, website); err != nil {
return err
}
return nil
diff --git a/agent/init/migration/migrations/init.go b/agent/init/migration/migrations/init.go
index 79e579d00..bacc40c47 100644
--- a/agent/init/migration/migrations/init.go
+++ b/agent/init/migration/migrations/init.go
@@ -297,7 +297,7 @@ var AddTask = &gormigrate.Migration{
}
var UpdateWebsite = &gormigrate.Migration{
- ID: "20240803-update-website",
+ ID: "20240807-update-website",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(
&model.Website{})
diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts
index 53056653d..b5e902ee0 100644
--- a/frontend/src/api/interface/website.ts
+++ b/frontend/src/api/interface/website.ts
@@ -288,6 +288,7 @@ export namespace Website {
SSLProtocol: string[];
algorithm: string;
hsts: boolean;
+ httpsPort: number;
}
export interface CheckReq {
diff --git a/frontend/src/views/website/website/config/basic/https/index.vue b/frontend/src/views/website/website/config/basic/https/index.vue
index 067022a9f..138771710 100644
--- a/frontend/src/views/website/website/config/basic/https/index.vue
+++ b/frontend/src/views/website/website/config/basic/https/index.vue
@@ -13,10 +13,13 @@