acme.sh can not renew the nginx server certification

If you have redirect port 80 to 443 at nginx.conf ,the renew will failed as

it gave error:

Cannot find config file for domain cloudzhong.top

Though it is already solved by another post

But the solution have issues, that I can only change the config to a renew config then renew certification and then rolled back the config file . to let the config file do not need to be rolled back , I write this post.

For nginx 80 port , add

 server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  cloudzhong.top;
        root         /usr/share/nginx/html;
        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }
        location ^~ /wordpress/ {
                return 403;
        }
    }

server_name need change to domainname, and root directive maybe is also needed.

and forbidden wordpress folder by return 403

and the below redirect code.

return 301 https://$host$request_uri; 

in the server 80 block is not allowed, this is the reason that acme.sh failed. So I delete it here.

add index.html under root folder.

here is the content:

<!DOCTYPE html>
<html>
<head>
        <meta http-equiv="refresh" content="0;url=https://cloudzhong.top">
        <title>it is redirectling...</title>
</head>
<body>
    <p>if this page did not redirect , please click <a href="https://cloudzhong.top">Here</a></p>
</body>
</html>

This is the automatically redirect html ,which will works same as return 301 when access domain name by http.

Then you can successfully renew the certification.

Leave a Reply