How do I create automatic SSL renewals with certbot
Hello, I am very glad to receive your reply. I reinstalled my cloud server and tried the operation again. The operation is as follows。
1 # 更新软件包列表
2 sudo apt update
3 # 升级已安装的软件包
4 sudo apt upgrade -y
5 # 安装 Nginx 服务器
6 sudo apt install nginx -y
7 # 添加 Certbot 软件源
8 sudo apt install certbot python3-certbot-nginx -y
9 # 编辑 Nginx 配置文件
10 sudo nano /etc/nginx/sites-available/a01.sj.js.cn
11 sudo ln -s /etc/nginx/sites-available/a01.sj.js.cn /etc/nginx/sites-enabled/
12 sudo nginx -t
13 sudo systemctl restart nginx
14 # 创建验证目录
15 sudo mkdir -p /var/www/html/.well-known/acme-challenge
16 # 设置目录权限
17 sudo chown -R www-data:www-data /var/www/html
18 sudo chmod -R 755 /var/www/html
19 sudo certbot --nginx -d a01.sj.js.cn
20 ping a01.sj.js.cn
21 dig a01.sj.js.cn
22 sudo tail -n 50 /var/log/letsencrypt/letsencrypt.log
23 history
Here is my nginx configuration information:
server {
listen 80;
server_name a01.sj.js.cn;
# 配置 Let's Encrypt 验证路径
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /var/www/html;
}
# 其他配置
location / {
# 这里可以添加你的网站配置
return 301 https://$host$request_uri; # 重定向到 HTTPS
}
}
Also this is my log file information:
ison@ali-01:~$ sudo tail -n 100 /var/log/letsencrypt/letsencrypt.log
2025-04-09 13:46:11,544:DEBUG:acme.client:Received response:
HTTP 200
Server: nginx
Date: Wed, 09 Apr 2025 05:46:11 GMT
Content-Type: application/json
Content-Length: 1024
Connection: keep-alive
Boulder-Requester: 2330585977
Cache-Control: public, max-age=0, no-cache
Link: https://acme-v02.api.letsencrypt.org/directory;rel="index"
Replay-Nonce: 6Oat0CnApgCpxt7kNThTGt9Dq4104-RuKbJdQQSKbopc-YpusQ8
X-Frame-Options: DENY
Strict-Transport-Security: max-age=604800
{
"identifier": {
"type": "dns",
"value": "a01.sj.js.cn"
},
"status": "invalid",
"expires": "2025-04-16T05:46:07Z",
"challenges": [
{
"type": "http-01",
"url": "https://acme-v02.api.letsencrypt.org/acme/chall/2330585977/502726103917/LrSO6Q",
"status": "invalid",
"validated": "2025-04-09T05:46:09Z",
"error": {
"type": "urn:ietf:params:acme:error:unauthorized",
"detail": "47.108.73.109: Invalid response from http://a01.sj.js.cn/.well-known/acme-challenge/Bw9Qu7Op8TkkT_zZCT6VO_z8P45jVm5e8GBEviwiM08: 403",
"status": 403
},
"token": "Bw9Qu7Op8TkkT_zZCT6VO_z8P45jVm5e8GBEviwiM08",
"validationRecord": [
{
"url": "http://a01.sj.js.cn/.well-known/acme-challenge/Bw9Qu7Op8TkkT_zZCT6VO_z8P45jVm5e8GBEviwiM08",
"hostname": "a01.sj.js.cn",
"port": "80",
"addressesResolved": [
"47.108.73.109"
],
"addressUsed": "47.108.73.109"
}
]
}
]
}
2025-04-09 13:46:11,544:DEBUG:acme.client:Storing nonce: 6Oat0CnApgCpxt7kNThTGt9Dq4104-RuKbJdQQSKbopc-YpusQ8
2025-04-09 13:46:11,544:INFO:certbot._internal.auth_handler:Challenge failed for domain a01.sj.js.cn
2025-04-09 13:46:11,544:INFO:certbot._internal.auth_handler:http-01 challenge for a01.sj.js.cn
2025-04-09 13:46:11,545:DEBUG:certbot._internal.display.obj:Notifying user:
Certbot failed to authenticate some domains (authenticator: nginx). The Certificate Authority reported these problems:
Domain: a01.sj.js.cn
Type: unauthorized
Detail: 47.108.73.109: Invalid response from http://a01.sj.js.cn/.well-known/acme-challenge/Bw9Qu7Op8TkkT_zZCT6VO_z8P45jVm5e8GBEviwiM08: 403
Hint: The Certificate Authority failed to verify the temporary nginx configuration changes made by Certbot. Ensure the listed domains point to this nginx server and that it is accessible from the internet.
2025-04-09 13:46:11,546:DEBUG:certbot._internal.error_handler:Encountered exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/certbot/_internal/auth_handler.py", line 106, in handle_authorizations
self._poll_authorizations(authzrs, max_retries, best_effort)
File "/usr/lib/python3/dist-packages/certbot/_internal/auth_handler.py", line 206, in _poll_authorizations
raise errors.AuthorizationError('Some challenges have failed.')
certbot.errors.AuthorizationError: Some challenges have failed.
2025-04-09 13:46:11,547:DEBUG:certbot._internal.error_handler:Calling registered functions
2025-04-09 13:46:11,547:INFO:certbot._internal.auth_handler:Cleaning up challenges
2025-04-09 13:46:12,663:DEBUG:certbot._internal.log:Exiting abnormally:
Traceback (most recent call last):
File "/usr/bin/certbot", line 33, in
sys.exit(load_entry_point('certbot==2.1.0', 'console_scripts', 'certbot')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/certbot/main.py", line 19, in main
return internal_main.main(cli_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/certbot/_internal/main.py", line 1736, in main
return config.func(config, plugins)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/certbot/_internal/main.py", line 1440, in run
new_lineage = _get_and_save_cert(le_client, config, domains,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/certbot/_internal/main.py", line 138, in _get_and_save_cert
lineage = le_client.obtain_and_enroll_certificate(domains, certname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/certbot/_internal/client.py", line 516, in obtain_and_enroll_certificate
cert, chain, key, _ = self.obtain_certificate(domains)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/certbot/_internal/client.py", line 428, in obtain_certificate
orderr = self._get_order_and_authorizations(csr.data, self.config.allow_subset_of_names)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/certbot/_internal/client.py", line 496, in _get_order_and_authorizations
authzr = self.auth_handler.handle_authorizations(orderr, self.config, best_effort)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/certbot/_internal/auth_handler.py", line 106, in handle_authorizations
self._poll_authorizations(authzrs, max_retries, best_effort)
File "/usr/lib/python3/dist-packages/certbot/_internal/auth_handler.py", line 206, in _poll_authorizations
raise errors.AuthorizationError('Some challenges have failed.')
certbot.errors.AuthorizationError: Some challenges have failed.
2025-04-09 13:46:12,665:ERROR:certbot._internal.log:Some challenges have failed.