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
,我已经将它们设置为 chmod755
.我不知道还需要设置什么.
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
.您可以通过运行
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屋!