Django – Fixing Permission Problems with Nginx and FastCGI via Unix Sockets

djangofastcginginxpython

I've configured nginx to run django site via socket:

fastcgi_pass unix:/tmp/django.socket;

now I'm (manually) running

./manage.py runfcgi socket=/tmp/django.socket

http request results in 502 bad gateway, and the error is following:

connect() to unix:/tmp/django.socket failed (13: Permission denied)
while connecting to upstream,

what permissions should I set, to be able to restart django fcgi easily?

Best Answer

Nginx is running under some user (on Debian it is usually www-data), you can check it by:

ps aux | grep nginx | grep worker

User will be in the first column.

This user have to have access to /tmp/django.socket for writing and reading. You can solve it by running django under the same user as nginx is running (i.e. www-data on Debian), or you have to add nginx user to the same group, as user, under which are you running django, and socket have to have permission to read and write for group.

The first solution is simplier and (for me) better.