From ff575e59634fa207f847829f225d63a10b2684e0 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Thu, 24 Nov 2022 14:58:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=82=E9=85=8D=20=E8=AF=81=E4=B9=A6?= =?UTF-8?q?=20HTTP=20=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/nginx/versions/1.23.1/conf/conf.d/default.conf | 13 +++++++++++++ apps/nginx/versions/1.23.1/docker-compose.yml | 3 ++- backend/app/service/website_ssl.go | 12 ++++++++++++ backend/utils/ssl/client.go | 12 +++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/apps/nginx/versions/1.23.1/conf/conf.d/default.conf b/apps/nginx/versions/1.23.1/conf/conf.d/default.conf index e69de29bb..bb0d1f3a2 100644 --- a/apps/nginx/versions/1.23.1/conf/conf.d/default.conf +++ b/apps/nginx/versions/1.23.1/conf/conf.d/default.conf @@ -0,0 +1,13 @@ +server { + listen 80 default_server; + server_name _; + charset utf-8; + default_type text/html; + + location ~ /.well-known/acme-challenge { + allow all; + root /usr/share/nginx/html; + } + + root /usr/share/nginx/html; +} \ No newline at end of file diff --git a/apps/nginx/versions/1.23.1/docker-compose.yml b/apps/nginx/versions/1.23.1/docker-compose.yml index 94f7ab59c..ac972f049 100644 --- a/apps/nginx/versions/1.23.1/docker-compose.yml +++ b/apps/nginx/versions/1.23.1/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: nginx1.23.1: - container_name: ${CONTAINER_NAME} + container_name: nginx1.23.1 image: nginx:1.23.1 restart: always network_mode: host @@ -11,5 +11,6 @@ services: - ./conf/conf.d:/etc/nginx/conf.d/ - ./ssl:/etc/nginx/ssl - ./www:/www/root/ + - ./root:/usr/share/nginx/html diff --git a/backend/app/service/website_ssl.go b/backend/app/service/website_ssl.go index 2428d31e9..1ba5e1fc6 100644 --- a/backend/app/service/website_ssl.go +++ b/backend/app/service/website_ssl.go @@ -6,7 +6,9 @@ import ( "encoding/pem" "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/model" + "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/utils/ssl" + "path" "strings" ) @@ -66,6 +68,16 @@ func (w WebSiteSSLService) Create(create dto.WebsiteSSLCreate) (dto.WebsiteSSLCr return res, err } case dto.Http: + + appInstall, err := getAppInstallByKey("nginx") + if err != nil { + return dto.WebsiteSSLCreate{}, err + } + + if err := client.UseHTTP(path.Join(constant.AppInstallDir, "nginx", appInstall.Name, "root")); err != nil { + return res, err + } + case dto.DnsManual: } diff --git a/backend/utils/ssl/client.go b/backend/utils/ssl/client.go index fc12183d4..d4b29336b 100644 --- a/backend/utils/ssl/client.go +++ b/backend/utils/ssl/client.go @@ -9,6 +9,7 @@ import ( "github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/providers/dns/alidns" "github.com/go-acme/lego/v4/providers/dns/dnspod" + "github.com/go-acme/lego/v4/providers/http/webroot" "github.com/go-acme/lego/v4/registration" "github.com/pkg/errors" "time" @@ -120,8 +121,17 @@ func (c *AcmeClient) UseManualDns(domains []string) (*Resolve, error) { return p.Resolve, nil } -func (c *AcmeClient) UseHTTP() { +func (c *AcmeClient) UseHTTP(path string) error { + httpProvider, err := webroot.NewHTTPProvider(path) + if err != nil { + return err + } + err = c.Client.Challenge.SetHTTP01Provider(httpProvider) + if err != nil { + return err + } + return nil } func (c *AcmeClient) ObtainSSL(domains []string) (certificate.Resource, error) {