When running Let's Encrypt with nginx, if we get the error 404
at .well-known/acme-challenge
try running it using the command below with nginx stopped.
systemctl stop nginx
certbot certonly --standalone -d example.com --non-interactive --agree-tos --email support@example.com
systemctl start nginx
This should pass the verification step which otherwise will error with 404 issue.
Update nginx conf.d
configuration to have the below lines.
server {
index index.html index.htm;
server_name example.com;
# ..
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com;
return 404; # managed by Certbot
}