Nginx configuration, folder permissions and encryption

I am trying to use certbot and letencrypt on my Ubuntu 16.0.4 server, so I can install a mail server.

I run certbot as follows:

sudo / opt / letencrypt / certbot-aut certonly --agree-tos --webroot -w / path / to / www / example -d example.com -d www.example.com

I get the following result from certbot (snippet below):

   Domain: www.example.com
   Type:   unauthorized
   Detail: Invalid response from
   http://www.example.com/.well-known/acme-challenge/QEZwFgUGOJqqXHcLmTmkr5z83dbH3QlrIUk1S3JI_cg:
   "<html>
   <head><title>404 Not Found</title></head>
   <body bgcolor="white">
   <center><h1>404 Not Found</h1></center>
   <hr><center>"

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A record(s) for that domain
   contain(s) the right IP address.

This is what my directory structure looks like:

root@yourbox:/path/to/www/example$ ls -la
total 12
drwxr-xr-x 3 example root    4096 Nov  1 10:17 .
drwxr-xr-x 5 root        webapps 4096 Nov  1 10:13 ..
drwxr-xr-x 2 root        root    4096 Nov  1 10:36 .well-known
root@yourbox:/path/to/www/example$ 
root@yourbox:/path/to/www/example$ cd .well-known/
root@yourbox:/path/to/www/example/.well-known$ ls -la
total 8
drwxr-xr-x 2 root        root 4096 Nov  1 10:36 .
drwxr-xr-x 3 example root 4096 Nov  1 10:17 ..
root@yourbox:/path/to/www/example/.well-known$ 

From above, I see that the task file does not exist (presumably?), Because it looks like certbot cannot write to the folder.

However, I first needed to verify that nginx was configured correctly and that it serves files from folders starting from the period.

This is the configuration file for nginx for the website (/ etc / nginx / sites-available / example):

server {
    # Allow access to the letsencrypt ACME Challenge
    location ~ /\.well-known\/acme-challenge {
        allow all;
    }
}

(sudo touch/path/to/www/example/fake) :

root@yourbox:/path/to/www/example/.well-known/acme-challenge$ ls -l
total 0
-rw-r--r-- 1 example webapps 0 Nov  1 10:45 fake

http://www.example.com/.well-known/acme-challenge/fake - 404.

, :

  • Nginx .well-known/acme-challenge
  • /path/to/www/example , certbot .well-known/acme-challenge.

?

+4
1

Nginx , /path/to/www/example/directory.

​​ , LetsEncyrpt . 80.

server {
    listen 80;

    server_name www.example.co.uk example.co.uk;

    root /path/to/www/example;

    access_log /var/log/nginx/example.co.uk.log;
    error_log /var/log/nginx/example.co.uk.log;

    index index.html index.htm index.php;

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

    location / {
        try_files $uri $uri/index.html $uri.html =404;
    }
}

_ /etc/hosts .

+2

Source: https://habr.com/ru/post/1659507/


All Articles