@@ -46,6 +46,15 @@ local function renew_check_cert_unlock(domain, storage, local_lock, distributed_
4646 end
4747end
4848
49+ local function delete_cert_if_expired (domain , storage , cert )
50+ -- Give up on renewing this certificate if we didn't manage to renew
51+ -- it before the expiration date
52+ if cert [" expiry" ] and cert [" expiry" ] < ngx .now () then
53+ ngx .log (ngx .WARN , " auto-ssl: existing certificate is expired, deleting: " , domain )
54+ storage :delete_cert (domain )
55+ end
56+ end
57+
4958local function renew_check_cert (auto_ssl_instance , storage , domain )
5059 -- Before issuing a cert, create a local lock to ensure multiple workers
5160 -- don't simultaneously try to register the same cert.
@@ -138,6 +147,7 @@ local function renew_check_cert(auto_ssl_instance, storage, domain)
138147 local allow_domain = auto_ssl_instance :get (" allow_domain" )
139148 if not allow_domain (domain , auto_ssl_instance , nil , true ) then
140149 ngx .log (ngx .NOTICE , " auto-ssl: domain not allowed, not renewing: " , domain )
150+ delete_cert_if_expired (domain , storage , cert )
141151 renew_check_cert_unlock (domain , storage , local_lock , distributed_lock_value )
142152 return
143153 end
@@ -175,13 +185,7 @@ local function renew_check_cert(auto_ssl_instance, storage, domain)
175185 local _ , issue_err = ssl_provider .issue_cert (auto_ssl_instance , domain )
176186 if issue_err then
177187 ngx .log (ngx .ERR , " auto-ssl: issuing renewal certificate failed: " , issue_err )
178-
179- -- Give up on renewing this certificate if we didn't manage to renew
180- -- it before the expiration date
181- if cert [" expiry" ] and cert [" expiry" ] < ngx .now () then
182- ngx .log (ngx .WARN , " auto-ssl: existing certificate is expired, deleting: " , domain )
183- storage :delete_cert (domain )
184- end
188+ delete_cert_if_expired (domain , storage , cert )
185189 end
186190
187191 renew_check_cert_unlock (domain , storage , local_lock , distributed_lock_value )
0 commit comments