Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.well-known/acme-challenge nginx 404 error

I'm trying to verify a file upload for SSL certificate. The file needs to be .well-known/acme-challenge/file

I have successfully placed the file as above, but while accessing the same file from the web http://weburl.com/.well-known/acme-challenge/file, 404 error is coming up. When I place the same file in .well-known/ the file can be access from the path http://weburl.com/.well-known/file successfully.

My nginx configuration:

server {
        listen 80;

        server_name weburl.com; 
        root /var/www/html;

        location ~ /.well-known {
                allow all;
        }

        location ~ /\.well-known/acme-challenge/ {
            allow all;
            root /var/www/html;
            try_files $uri =404;
            break;
        }
}
like image 239
Matey Johnson Avatar asked May 30 '18 10:05

Matey Johnson


Video Answer


2 Answers

You have to grant permissions for www-data user.

sudo chown -R www-data:www-data .well-known 
like image 100
northtree Avatar answered Oct 20 '22 04:10

northtree


In the first case it looks for /var/www/html/.well-known/file.

In the second case it looks for /var/www/html/file.

What you intend is for it to find /var/www/html/.well-known/acme-challenge/file

This is because you specify root in the location block, which changes where it reads the file from.

So instead of this:

    location ~ /\.well-known/acme-challenge/ {
        allow all;
        root /var/www/html; # <================= Your problem, sir
        try_files $uri =404;
        break;
    }

You should have this:

    location ~ /\.well-known/acme-challenge/ {
        allow all;
        try_files $uri =404;
        break;
    }

Shameless plug: If you're just doing simple virtual hosting and you're familiar with node at all you might like Greenlock.

like image 2
coolaj86 Avatar answered Oct 20 '22 03:10

coolaj86