Nginx Resolution (404)

An attempt to obtain encryption using the webroot method, which creates and needs access to files in a directory. /.well-known/acme-challenge/. Everything that is (including the manual verification file that I added) is displayed as 404.

Going crazy as I tried the options:

location ~ /.well-known {
    allow all;
}
location /.well-known/acme-challenge {
    default_type text/plain;
}
location /.well-known {
    try_files $uri $uri/ =404;
}

bad luck. I also checked folder permissions and even installed 777. I am new to configuring nginx, so I'm sure there is an existing condition that discards it:

server{
    listen 80;
    server_name domain.com www.domain.com;
    location / {
        rewrite ^(.*)$ https://domain.com$1 permanent;
    }
    location ~ /.well-known {
            allow all;
    }
}

server {
        listen 0.0.0.0:443 ssl;
        root /var/www/domain.com/public_html;
        index index.php index.html index.htm;
        server_name domain.com www.domain.com;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                client_max_body_size 32m;
        }
        location ~ /.well-known {
            allow all;
        }
}
+4
source share
2 answers

Your first block serverrequires a directive rootto resolve local files.

. .

+5

, root. server location.

, root location, "/.well-known"

location ~ /.well-known {
    allow all;
    root /var/www/domain.com/public_html;

    # NOT
    # root /var/www/domain.com/public_html/.well-known;
}
+7

All Articles