2017-09-16 79 views
0

我無法讓nginx返回我在/var/www/letsencrypt中輸入的文件。配置Nginx回覆http://my-domain.com/.well-known/acme-challenge/XXXX

的nginx /網站可用/ 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 /段/ 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.任何想法我失蹤?

回答

0

選項root /var/www/letsencrypt/;告訴nginx「這是基礎目錄」,所以最終路徑將是/var/www/letsencrypt/.well-known/acme-challenge/

所以,你有兩個選擇:

  1. 更改路徑,例如Nginx的

    $ echo hi > /var/www/letsencrypt/.well-known/acme-challenge/hi 
    
  2. 改變行爲,所以nginx的將其當作別名:

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

而且不要原諒et使killall -1 nginx重新加載配置