SSL - Certbot: 404 / unauthorized

I understand why some people wish to hide that they have problems. But, you used a domain name that was valid and belongs to someone else. Now their name shows up in such searches. You should use example.com for example domain names. But hiding your actual name makes it more difficult for volunteers to help. Some of us are less excited about helping when the person wanting help makes it difficult.

That said

Isn't the file name abc.txt ? You are missing the trailing "t". Or is that just you making a mistake when trying to hide info?

3 Likes

Ok got it, I'll use example.com

Regarding the tx... Looks like I made a typo in the console. It actually does work when using txt, my bad :confused:

So yes: I can create a txt file on the server and have it displayed in the browser when querying the challenge url

Thanks to your help, I've been able to make some progress and I'm now in a weird situation:

  • I'm still getting the same error as before

Certbot failed to authenticate some domains
Type: unauthorized
Invalid response from http://example.com/.well-known/acme-challenge/bg804B2Sw2ayJ7WwTiXiS_HixTg87PIJSA_izTjL6ik: 404

  • HOWEVER: in letsencrypt logs, I can read this:

2024-03-21 10:12:07,928:DEBUG:certbot._internal.plugins.webroot:Removing /home/ec2-user/example-ui/var/www/certbot/.well-known/acme-challenge/bg804B2Sw2ayJ7WwTiXiS_HixTg87PIJSA_izTjL6ik

And in nginx logs:

2024/03/21 10:28:20 [error] 29#29: *9 open() "/home/ec2-user/example-ui/var/www/certbot/.well-known/acme-challenge/bg804B2Sw2ayJ7WwTiXiS_HixTg87PIJSA_izTjL6ik:" failed (2: No such file or directory), client: 184.105.99.36, server: example.com, request: "GET /.well-known/acme-challenge/bg804B2Sw2ayJ7WwTiXiS_HixTg87PIJSA_izTjL6ik: HTTP/1.1", host: "example.com"

So I dont get this: challenge files seem to be created (since the logs say they are later removed) but the request cant find them, how is that possible?
I'm lost cause the error message mentions both "404" and "unauthorized". Which is it?

Thanks for the help

1 Like

I'm a little puzzled by the path that Certbot used. In an earlier nginx server block you have the acme challenge path as /var/www/certbot but the path Certbot used is not that. The path Certbot uses and the path you have configured as the root in nginx must match.

In your manual test you created a file in /var/www/certbot.

What was the Certbot command you used?

2 Likes

Hello Mike!
I actually just managed to make it work... that's quite a pleasant surprise!
Issue was the following: although the paths certbot and nginx use were the 'same', one path was outside the container (certbot) and one was inside (nginx)...
That's because I'm starting my project + nginx by using docker-compose, and only when it's launched I use the following command:

sudo certbot -v certonly --webroot -w ./var/www/certbot -d example.com -d www.example.com --dry-run

Most tutorial I read online advise to use certbot image and start the container of the project with a command that executes the challenge on launch, but in my case certbot wasnt working automatically, challenge had to be done manually. No idea why it didnt work automatically

I know that this whole thread might be confusing for people who would read it in the future. I struggled cause I had zero prior experience with docker, nginx, aws and certificates... but I'd like to give just a few comments based on my experience:

  • If you use Docker volumes, double check that your volumes are correctly mounted. In my case, they initially werent
  • Be careful with permissions: the folder to which challenge files are supposed to be written wasnt authorizing it first, I had to change permissions
  • Check logs from both letsencrypt and nginx, they show which folders are used to write / retrieve challenge files. If there's any discrepency, you can figure it out there

Thanks again for the help

1 Like

You should use a fully qualified path for webroot path. The leading '.' prefixes the current working folder. That's just normal linux format not unique to Certbot.

Running a certbot renew or other commands may run in a different context which would cause problems.

2 Likes

I don't know if this is the case, but Certbot might expand the relative path before storing it, e.g. using some Python version of realpath. Could test this when I'm back at home.

1 Like

Sure, it might. But if us experts aren't sure how it behaves today I think it best not to rely on that :slight_smile:

2 Likes

+

If those are provided as "instructions to others", their results may vary greatly.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.