Permission denied when Nginx tries to write image file
You gave the directory the wrong permissions. 0600
will give read and write permissions to the directory. But to access a directory, you also need execute permission. Here's an example:
[jenny@temeraire sf] $ mkdir test1
[jenny@temeraire sf] $ chmod 0600 test1
[jenny@temeraire sf] $ touch test1/foo
touch: test1/foo: Permission denied
[jenny@temeraire sf] $ chmod 0700 test1
[jenny@temeraire sf] $ touch test1/foo
[jenny@temeraire sf] $ ls -ld test1/foo
-rw-r--r-- 1 jenny staff 0 Jun 5 07:46 test1/foo
Related videos on Youtube
Joshua Rajandiran
Updated on September 18, 2022Comments
-
Joshua Rajandiran over 1 year
I'm using Nginx for a Linux server and I have this folder
/usr/local/openresty/nginx/webfolder/img
where I want nginx to save my uploaded image files.So, this is what I did:
1) I changed the owner of the directory to
www-data
user inwww-data
group:chown -R www-data:www-data /usr/local/openresty/nginx/webfolder/img
2) Then I updated the permissions of the directory:
sudo chmod 0600 /usr/local/openresty/nginx/webfolder/img
Lua upload err part (where I log the err):
fileToSave, errMessage = io.open(savefiletarget, "w+b") if not fileToSave then --ngx.say("failed to open file ", savefiletarget) ngx.log(ngx.NOTICE,'failed to save file : '..savefiletarget..' reason: '..errMessage); ngx.say('{"filename" : "'..filenametosave..'","status" : 0 ,"message":"failed to open file"}') return end
Right now my error log still shows
Permission Denied
when I try to upload the file.I assume
www-data
is the user that nginx uses right? So why I'm not able to still write the file? -
Joshua Rajandiran almost 6 yearsThanks, it worked btw I'd like to add that my nginx.conf file also didnt have the
www-data
group and user specified. Nginx was usingnobody
for the worker processes. Btw, I also reset the owner of the directory back toroot
and only changed the permissions viachmod
command. Worked for me.