fix: ACME HTTP-01 via nginx config without HTTPS redirect

This commit is contained in:
orohi
2026-06-17 06:12:54 +03:00
parent f2c05d15ec
commit 0000a8974d
8 changed files with 239 additions and 26 deletions
+24 -3
View File
@@ -7,6 +7,7 @@ import (
"time"
"github.com/panelhosting/panel/internal/config"
"github.com/panelhosting/panel/internal/nginx"
"github.com/panelhosting/panel/internal/repository"
"github.com/panelhosting/panel/internal/ssl"
)
@@ -15,11 +16,12 @@ type Service struct {
repo *repository.SSLRepository
sites *repository.SiteRepository
issuer *ssl.Issuer
nginx *nginx.Manager
cfg *config.Config
}
func NewService(repo *repository.SSLRepository, sites *repository.SiteRepository, issuer *ssl.Issuer, cfg *config.Config) *Service {
return &Service{repo: repo, sites: sites, issuer: issuer, cfg: cfg}
func NewService(repo *repository.SSLRepository, sites *repository.SiteRepository, issuer *ssl.Issuer, ngx *nginx.Manager, cfg *config.Config) *Service {
return &Service{repo: repo, sites: sites, issuer: issuer, nginx: ngx, cfg: cfg}
}
func (s *Service) IssueAsync(sslID, domainID int64, domain, webroot, email string) {
@@ -45,6 +47,15 @@ func (s *Service) Issue(ctx context.Context, sslID, domainID int64, domain, webr
return s.repo.MarkError(ctx, sslID, "укажите email для Let's Encrypt")
}
if s.nginx.Enabled() {
if err := s.nginx.PrepareHTTPChallenge(domain, webroot); err != nil {
msg := "nginx: " + err.Error()
_ = s.repo.MarkError(ctx, sslID, msg)
return err
}
time.Sleep(2 * time.Second)
}
res, err := s.issuer.Obtain(ctx, email, domain, webroot)
if err != nil {
_ = s.repo.MarkError(ctx, sslID, err.Error())
@@ -61,7 +72,17 @@ func (s *Service) Issue(ctx context.Context, sslID, domainID int64, domain, webr
issuerName = "Let's Encrypt (staging)"
}
return s.repo.MarkActive(ctx, sslID, issuerName, string(res.Certificate), string(res.PrivateKey), string(res.IssuerCertificate), time.Now(), expiresAt)
if err := s.repo.MarkActive(ctx, sslID, issuerName, string(res.Certificate), string(res.PrivateKey), string(res.IssuerCertificate), time.Now(), expiresAt); err != nil {
return err
}
if s.nginx.Enabled() {
if err := s.nginx.ApplyHTTPS(domain, webroot); err != nil {
log.Printf("nginx apply https %s: %v", domain, err)
}
}
return nil
}
func (s *Service) IssueForSite(ctx context.Context, siteID int64, email string) error {