I am using the default config while adding the specific directory with nginx installed on my ubuntu 12.04 machine.
server {
#listen 80; ## listen
By default the static data, when you install the nginx, will be in /var/www/html. So you can just copy your static folder into /var/html/ and set the
root /var/www/<your static folder>
in ngix.conf (or /etc/nginx/sites-available/default)
This worked for me on ubuntu but I guess it should not be much different for other distros.
Hope it helps.
Nginx need to have +x access on all directories leading to the site's root directory.
Ensure you have +x on all of the directories in the path leading to the site's root. For example, if the site root is /home/username/siteroot:
chmod +x /home/
chmod +x /home/username
chmod +x /home/username/siteroot
I've just had the same problem on a CentOS 7 box.
Seems I'd hit selinux. Putting selinux into permissive mode (setenforce permissive
) has worked round the problem for now. I'll try and get back with a proper fix.
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
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.
The best solution in that case would be to add www-data
to username
group:
gpasswd -a www-data 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
For your changes to work, restart nginx
nginx -s reload
In my case, the folder which served the files was a symbolic link to another folder, made with
ln -sf /origin /var/www/destination
Even though the permissions (user and group) where correct on the destination folder (the symbolic link), I still had the error because Nginx needed to have permissions to the origin folder whole's hierarchy as well.
Symptom:
Could not upload images to WordPress Media Library.
Cause:
(CentOS) yum update
Error:
2014/10/22 18:08:50 [crit] 23286#0: *5332 open() "/var/lib/nginx/tmp/client_body/0000000003" failed (13: Permission denied), client: 1.2.3.4, server: _, request: "POST /wp-admin/media-new.php HTTP/1.1", host: "example.com", referrer: "http://example/wp-admin/media-new.php"
Solution:
chown -R www-data:www-data /var/lib/nginx