get "/.well-known/acme-challenge/@challenge":
writeFile(getCurrentDir() / @"challenge", @"challenge")
sendFile getCurrentDir() / @"challenge"
which works if used with browser but doesn’t work with certbotI would let your webserver handle those requests, nginx for example. When you use nginx then you could even use certbot's nginx plugin.
Anyhow, those challenges must be served via http not https.
Using certbot with nginx is pretty automatic and easy. https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/
Making your own certbot like tool sounds really hard.
Here's my nginx setup -
server {
client_max_body_size 64M;
listen 80;
server_name sub.mydomain.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_read_timeout 60;
proxy_connect_timeout 60;
proxy_redirect off;
# Allow the use of websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
How can I make it work with automatic certbot register and renew?Aside from installing certbot nginx plugin, I have been using plain nginx server to serve ACME challenge on Arch linux for many years. All I do is to bare an empty directory (e.g. /srv/certbot) for nginx to serve static files and ask certbot to save the challenge response to that directory.
server {
listen 80;
listen [::]:80;
server_name sub.mydomain.com;
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /srv/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name sub.mydomain.com;
ssl_certificate /etc/letsencrypt/live/sub.mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sub.mydomain.com/privkey.pem;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:3000;
# websocket headers
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Scheme $scheme;
proxy_buffering off;
}
}
and use the following command for renewal.
sudo certbot certonly --webroot -w /srv/certbot/ -d sub.mydomain.com
Of course put the above in crontab and also call nginx -s reload later, otherwise nginx is still serving the old cert.
minor correction.
Of course put certbot renew in crontab and it is recommended to renew once a day and avoid to renew at XX:00 sharp to reduce surge to letsencrypt server.