Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Nginx is not able to write to log file even if its user has write group access. Here are some details:

www-data user is in ubuntu group:

$ id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data),1000(ubuntu)

/opt/logs/ is group writable:

$ ls -ld /opt/logs/
drwxrwxr-x 2 ubuntu ubuntu 4096 2012-07-27 02:47 /opt/logs/

www-data user can create /opt/logs/1 as expected:

$ su www-data
$ touch /opt/logs/1
$ ls -l /opt/logs/1
-rw-rw-r-- 1 www-data www-data 0 2012-07-27 02:47 /opt/logs/1

Nginx user:groups:

var_dump(system('whoami'), system('groups'));
// string 'www-data' (length=8)
// string 'www-data ubuntu' (length=15)

But Nginx is not able to write:

Warning: file_put_contents(/opt/logs/Error.log) function.file-put-contents failed to open stream: Permission denied

/opt/logs/Error.log doesn't exist

So why coudn't it write to file?

share|improve this question
    
any /opt/logs/Error.log exists ?, if yes, what's the permission ?. check if parent directory permission also. any apparmor or selinux ? –  chocripple Jul 27 '12 at 5:30
    
No, /opt/logs/Error.log doesn't exist. If it's apparmor or selinux, why can I create a file over shell? –  Roman Newaza Jul 27 '12 at 5:34
    
Furthermore, I chowned it to ubuntu:www-data and back to ubuntu:ubuntu and now it can write! –  Roman Newaza Jul 27 '12 at 5:35

1 Answer 1

up vote 1 down vote accepted

A possible reason: when you add www-data user to the ubuntu group, it only affects sessions started later.

su - www-data -s /bin/bash creates a new session, so it works fine. But Nginx is still running as www-data user, therefore I suspect that it's the reason for the above error.

(if you switch to the www-data user before doing a usermod -a -G ubuntu www-data, I'm pretty sure that you will only see uid=33(www-data) gid=33(www-data) groups=33(www-data) when typing id)

Either restarting Nginx or do a newgrp ubuntu after switching to www-data user to make it take effect immediately.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.