From e069db3c45e62dffd8b1be56993a9c4547c2146f Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 9 Oct 2024 14:42:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=8D=E4=BB=A3=E5=9B=9E=E6=BA=90=20?= =?UTF-8?q?SNI=20=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=20=20proxy=5Fssl=5Fn?= =?UTF-8?q?ame=20(#6659)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/5960 --- backend/app/dto/request/website.go | 31 ++++++++++--------- backend/app/service/website.go | 6 ++++ cmd/server/nginx_conf/proxy.conf | 1 + frontend/src/api/interface/website.ts | 2 ++ .../config/basic/proxy/create/index.vue | 8 ++++- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/backend/app/dto/request/website.go b/backend/app/dto/request/website.go index aac5baca1..4dbe8cc65 100644 --- a/backend/app/dto/request/website.go +++ b/backend/app/dto/request/website.go @@ -175,21 +175,22 @@ type WebsiteUpdateDirPermission struct { } type WebsiteProxyConfig struct { - ID uint `json:"id" validate:"required"` - Operate string `json:"operate" validate:"required"` - Enable bool `json:"enable" ` - Cache bool `json:"cache" ` - CacheTime int `json:"cacheTime" ` - CacheUnit string `json:"cacheUnit"` - Name string `json:"name" validate:"required"` - Modifier string `json:"modifier"` - Match string `json:"match" validate:"required"` - ProxyPass string `json:"proxyPass" validate:"required"` - ProxyHost string `json:"proxyHost" validate:"required"` - Content string `json:"content"` - FilePath string `json:"filePath"` - Replaces map[string]string `json:"replaces"` - SNI bool `json:"sni"` + ID uint `json:"id" validate:"required"` + Operate string `json:"operate" validate:"required"` + Enable bool `json:"enable" ` + Cache bool `json:"cache" ` + CacheTime int `json:"cacheTime" ` + CacheUnit string `json:"cacheUnit"` + Name string `json:"name" validate:"required"` + Modifier string `json:"modifier"` + Match string `json:"match" validate:"required"` + ProxyPass string `json:"proxyPass" validate:"required"` + ProxyHost string `json:"proxyHost" validate:"required"` + Content string `json:"content"` + FilePath string `json:"filePath"` + Replaces map[string]string `json:"replaces"` + SNI bool `json:"sni"` + ProxySSLName string `json:"proxySSLName"` } type WebsiteProxyReq struct { diff --git a/backend/app/service/website.go b/backend/app/service/website.go index a33c924ff..8c1466055 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -1667,6 +1667,9 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) } if req.SNI { location.UpdateDirective("proxy_ssl_server_name", []string{"on"}) + if req.ProxySSLName != "" { + location.UpdateDirective("proxy_ssl_name", []string{req.ProxySSLName}) + } } else { location.UpdateDirective("proxy_ssl_server_name", []string{"off"}) } @@ -1749,6 +1752,9 @@ func (w WebsiteService) GetProxies(id uint) (res []request.WebsiteProxyConfig, e if directive.GetName() == "proxy_ssl_server_name" { proxyConfig.SNI = directive.GetParameters()[0] == "on" } + if directive.GetName() == "proxy_ssl_name" { + proxyConfig.ProxySSLName = directive.GetParameters()[0] + } } res = append(res, proxyConfig) } diff --git a/cmd/server/nginx_conf/proxy.conf b/cmd/server/nginx_conf/proxy.conf index d939c3181..ce1203d24 100644 --- a/cmd/server/nginx_conf/proxy.conf +++ b/cmd/server/nginx_conf/proxy.conf @@ -11,4 +11,5 @@ location ^~ /test { add_header X-Cache $upstream_cache_status; add_header Cache-Control no-cache; proxy_ssl_server_name off; + proxy_ssl_name $proxy_host; } diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts index a7d7170b7..1864971cb 100644 --- a/frontend/src/api/interface/website.ts +++ b/frontend/src/api/interface/website.ts @@ -373,6 +373,8 @@ export namespace Website { content?: string; proxyAddress?: string; proxyProtocol?: string; + sni: boolean; + proxySSLName: string; } export interface ProxReplace { diff --git a/frontend/src/views/website/website/config/basic/proxy/create/index.vue b/frontend/src/views/website/website/config/basic/proxy/create/index.vue index 407afcdb9..ef0ce08a9 100644 --- a/frontend/src/views/website/website/config/basic/proxy/create/index.vue +++ b/frontend/src/views/website/website/config/basic/proxy/create/index.vue @@ -31,6 +31,9 @@ {{ $t('website.sniHelper') }} + + +