nginx返回404以获取有效的请求路径

时间:2015-12-14 15:42:21

标签: nginx

我打算在我的服务器上部署letsencrypt,但很快就失败了一个非常令人沮丧的错误。我设置了一个webroot并使用示例hello.txt文件对其进行了测试:

~]# cat /tmp/letsencrypt-auto/well-known/acme-challenge/hello.txt
hello
~]# ls -lZ /tmp/letsencrypt-auto/well-known/acme-challenge/hello.txt
-rw-rw-r--. martin martin unconfined_u:object_r:user_tmp_t:s0 /tmp/letsencrypt-auto/well-known/acme-challenge/hello.txt
~]# cat /etc/nginx/conf.d/site.conf
<truncated>
    location /well-known/acme-challenge {
        default_type  "text/plain";
        root          /tmp/letsencrypt-auto;
    }
<truncated>

但是,通过浏览到hello.txt来请求http://example.com/well-known/acme-challenge/hello.txt文件会在日志文件中返回404并出现此错误:

2015/12/14 10:39:42 [error] 5898#5898: *232 open() "/tmp/letsencrypt-auto/well-known/acme-challenge/hello.txt" failed (2: No such file or directory), client: XXX, server: XXX, request: "GET /well-known/acme-challenge/hello.txt HTTP/1.1", host: "XXX"

site.conf文件当然包含其他指令,但即使我将它们全部评论只留下/well-known...规则,它仍会返回404.任何想法可能导致这种情况?该文件显然存在,但感觉nginx无法看到它。关闭SELinux也没有帮助,顺便说一句。

1 个答案:

答案 0 :(得分:0)

事实证明,/tmp/的服务有点奇怪。当我将它移动到/srv/下我网站的位置时,一切正常。