I ran this command: certbot --nginx -d "example.com" -d "www.example.com"
It produced this output: Failed authorization procedure Invalid Response
My web server is: Nginx 1.14.0
The operating system my web server runs on is: Ubuntu 18.04
My hosting provider is: DigitalOcean
I can login to a root shell on my machine: yes
I’m using a control panel to manage my site: no
The version of my client is: certbot 0.31.0
From the logs, I’ve identified why the failure occurred, though I do not know how to fix it.
I have two server blocks in the configuration file: The first is simply for redirecting the non-WWW domain to the WWW one as shown below while the second is used for actually serving the site. Authorization succeeded for the WWW site but failed for the non-WWW site
server {
server_name example.com
return 301 $scheme://www.example.com$request_uri
}
The reason for this failure is due to how the certbot nginx plugin handled the authorization. It inserted the response for the acme-challenge after the return 301 as shown below:
server {
server_name example.com
return 301 $scheme://www.example.com$request_uri
location = /.well-known/acme-challenge/challengeurl{default_type text/plain;return 200 challengeresponse;} # Managed by Certbot
}
Since it is adding the challenge response return after the return 301, it will never reach that statement. Is there a way to force it to insert the location before the final return statement?
Thanks! That fixed that issue, but only for IPv4. For IPv6, it still will not work. In fact, when trying to diagnose the issue using curl, I found that it returned the actual webpage that the redirect would point to had nothing followed the domain name result of the redirection, not even the 301 redirect. Any ideas for how to fix this?
The full configuration file is below. Early on I did attempt to add the lines listen 80; and listen [::]:80 ipv6only=true to the first server block, but when I ran nginx -t it reported duplicate listens for [::]:80 .
In any case, I’m still a little confused why when accessing the non-WWW site using IPv6 I get the www site index page returned (HTTP 200) instead of a HTTP 301 to that page. If it wasn’t listeing on IPv6 at all, wouldn’t it just reset or refuse the connection?
This is a new site, so I hadn't even setup the database yet. I have now, so that error is now corrected. However, I still can't get the certificate to be issued. For example sake, I permanent added an example acme-challenge to the config. The output of my GET request using curl for both IPv4 and IPv6 is shown below:
I did it again just to be certain, and sure enough, as soon as I modify the config with both listen statements, running nginx -t resulted in the error
nginx: [emerg] duplicate listen options for [::]:80 in /etc/nginx/sites-enabled/netopalis.org:13
nginx: configuration file /etc/nginx/nginx.conf test failed