Nginx:stat()失败(13:权限被拒绝) [英] Nginx: stat() failed (13: permission denied)
问题描述
在使用ubuntu 12.04机器上安装了nginx的特定目录添加目录时,我正在使用默认配置.
I am using the default config while adding the specific directory with nginx installed on my ubuntu 12.04 machine.
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
root /username/test/static;
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
...
...
}
我只想要一个简单的静态nginx服务器来提供该目录之外的文件.但是,检查error.log
我看到的
I just want a simple static nginx server to serve files out of that directory. However, checking the error.log
I see
2014/09/10 16:55:16 [crit] 10808#0: *2 stat() "/username/test/static/index.html" failed (13: Permission denied), client:, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "domain"
2014/09/10 16:55:16 [error] 10808#0: *2 rewrite or internal redirection cycle while internally redirecting to "/index.html
我已经在/username/test/static
上完成了chown -R www-data:www-data
,将它们设置为chmod 755
.我不知道还需要设置什么.
I've already done chown -R www-data:www-data
on /username/test/static
, I've set them to chmod 755
. I don't know what else needs to be set.
推荐答案
Nginx在目录中运行,因此,如果您不能从nginx用户cd
到该目录,则它将失败(stat
也会失败)命令).确保www-user
可以一直cd
到/username/test/static
.您可以通过运行来确认stat
将失败还是成功
Nginx operates within the directory, so if you can't cd
to that directory from the nginx user then it will fail (as does the stat
command in your log). Make sure the www-user
can cd
all the way to the /username/test/static
. You can confirm that the stat
will fail or succeed by running
sudo -u www-data stat /username/test/static
在您的情况下,/username
目录可能是这里的问题.通常,www-data
无权将cd
授予其他用户主目录.
In your case probably the /username
directory is the issue here. Usually www-data
does not have permissions to cd
to other users home directories.
在这种情况下,最好的解决方案是将www-data
添加到username
组:
The best solution in that case would be to add www-data
to username
group:
gpasswd -a www-data username
,并确保username
组可以输入路径中的所有目录:
and make sure that username
group can enter all directories along the path:
chmod g+x /username && chmod g+x /username/test && chmod g+x /username/test/static
为使更改生效,请重新启动nginx
For your changes to work, restart nginx
nginx -s reload
这篇关于Nginx:stat()失败(13:权限被拒绝)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!