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
}
...
...
}
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
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.
Best Answer
Nginx operates within the directory, so if you can't
cd
to that directory from the nginx user then it will fail (as does thestat
command in your log). Make sure thewww-user
cancd
all the way to the/username/test/static
. You can confirm that thestat
will fail or succeed by runningIn your case probably the
/username
directory is the issue here. Usuallywww-data
does not have permissions tocd
to other users home directories.The best solution in that case would be to add
www-data
tousername
group:and make sure that
username
group can enter all directories along the path:For your changes to work, restart nginx