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.

KFSys
Site Moderator
Site Moderator badge
July 20, 2022
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.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel