Question

Django Permissions with Nginx and Gunicorn

I’m struggling on how to properly set up my directory and file permissions for my Django apps on my Droplet. I have both Nginx and Gunicorn. I tried setting the permissions on my Development Test machine at home to 755 for Directories and 644 for Files. I soon discovered my Virtual environment bin files would not execute properly. Should the bin files in VENV be set to higher than 644? Should the VENV directory and files have permissions other than 755/644? I do not want to break my apps in production. I’ve tried Google and searching for answers on this, but have not found much. Any ideas would be appreciated.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Hi @mpasquali,

The permissions you’ve used should be working well enough. What I think your issue at the moment is ownership. Is your ownership root:root on all your Django files? I’ll suggest checking the Nginx user and using that. If I’m not mistaken the Nginx user is www-data by default.

To change the ownership you can run:

  1. chown -R www-data:www-data /path/to/website

This will recursively change the user:group ownership of all folders under /path/to/website.