19

我无法让 nginx 返回我放入的文件/var/www/letsencrypt

nginx/sites-available/mydomain.conf

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;
  server_name my-real-domain.com;

  include /etc/nginx/snippets/letsencrypt.conf;

  root /var/www/mydomain;
  index index.html;
  location / {
    try_files $uri $uri/ =404;
  }
}

nginx/snippets/letsencrypt.conf

location ^~ /.well-known/acme-challenge/ {
  default_type "text/plain";
  root /var/www/letsencrypt;
}

我运行这个命令: certbot certonly --webroot -w /var/www/letsencrypt/ -d my-real-domain.com

但是 certbot 尝试访问的页面始终是 404。

调试

$ echo hi > /var/www/letsencrypt/hi
$ chmod 644 /var/www/letsencrypt/hi

现在我应该可以了curl localhost/.well-known/acme-challenge/hi,但这不起作用。仍然是 404。知道我错过了什么吗?

4

2 回答 2

26

选项root /var/www/letsencrypt/;告诉 nginx “这是基本目录”,所以最终路径将是/var/www/letsencrypt/.well-known/acme-challenge/.

因此,您有 2 个选择:

  1. 改变你的路径,例如

    $ echo hi > /var/www/letsencrypt/.well-known/acme-challenge/hi
    
  2. 改变 nginx 的行为,因此 nginx 会将其视为别名:

    location ^~ /.well-known/acme-challenge/ {
      default_type "text/plain";
      rewrite /.well-known/acme-challenge/(.*) /$1 break;
      root /var/www/letsencrypt;
    }
    

并且不要忘记 makekillall -1 nginx重新加载配置

于 2017-09-16T07:44:37.087 回答
0

看来 Synology Nginx 配置现在有一个 acme-challenge 规则。将文件放入/var/lib/letsencrypt/.well-known/acme-challenge,无需重新加载 Nginx,因为配置保持不变。

详情请参阅/etc/nginx/nginx.conf

于 2021-11-01T19:09:00.417 回答