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

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.