Letsencrypt Auto renewal fails - Error getting validation data

Isn’t this the same that is done when HTTPS redirect is disabled as per above?

I can only test your snippet when the next renewal is pending. For now all is working as the renewal was done manually.