Nginx权限问题(404)

时间:2016-02-27 10:20:19

标签: nginx lets-encrypt

尝试使用webroot方法设置let的加密设置,该方法创建并需要访问./.well-known/acme-challenge/目录中的文件。那里的一切(包括我添加的手动测试文件)都显示为404.

因为我尝试了以下变体而变得疯狂:

location ~ /.well-known {
    allow all;
}
location /.well-known/acme-challenge {
    default_type text/plain;
}
location /.well-known {
    try_files $uri $uri/ =404;
}
没有运气。我还检查了文件夹的权限,甚至设置为777.我很擅长设置nginx配置,所以我确信现有条件已经将其抛弃:

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;
        }
}

2 个答案:

答案 0 :(得分:9)

正如理查德史密斯所说,需要statusCode指令。它可以放在root块或server块中。

注意,即使location块中有root,路径也不应包含location

"/.well-known"

答案 1 :(得分:5)

您的第一个server块需要root指令才能解析本地文件。

有关详情,请参阅this document