@@ -46,6 +46,15 @@ local function renew_check_cert_unlock(domain, storage, local_lock, distributed_
46
46
end
47
47
end
48
48
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
+
49
58
local function renew_check_cert (auto_ssl_instance , storage , domain )
50
59
-- Before issuing a cert, create a local lock to ensure multiple workers
51
60
-- don't simultaneously try to register the same cert.
@@ -138,6 +147,7 @@ local function renew_check_cert(auto_ssl_instance, storage, domain)
138
147
local allow_domain = auto_ssl_instance :get (" allow_domain" )
139
148
if not allow_domain (domain , auto_ssl_instance , nil , true ) then
140
149
ngx .log (ngx .NOTICE , " auto-ssl: domain not allowed, not renewing: " , domain )
150
+ delete_cert_if_expired (domain , storage , cert )
141
151
renew_check_cert_unlock (domain , storage , local_lock , distributed_lock_value )
142
152
return
143
153
end
@@ -175,13 +185,7 @@ local function renew_check_cert(auto_ssl_instance, storage, domain)
175
185
local _ , issue_err = ssl_provider .issue_cert (auto_ssl_instance , domain )
176
186
if issue_err then
177
187
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 )
185
189
end
186
190
187
191
renew_check_cert_unlock (domain , storage , local_lock , distributed_lock_value )
0 commit comments