Question

Setting up django on nginx, ran in error: "can't chdir to ..."

I was following this tutorial: https://www.howtoforge.com/how-to-install-django-on-centos-8/ on how to set up django on nginx with gunicorn but ran into the following error:

[user@centos-s-1vcpu-2gb-fra1-01 ~]$ systemctl status django
● django.service - django daemon
   Loaded: loaded (/etc/systemd/system/django.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2020-09-02 19:44:16 UTC; 6s ago
  Process: 4615 ExecStart=/usr/local/bin/gunicorn --workers 3 --bind unix:/home/user/djangoprojects/djangoproject.sock djangoproject.wsgi:application (code=exited, status=1/FAILURE)
 Main PID: 4615 (code=exited, status=1/FAILURE)

Sep 02 19:44:15 centos-s-1vcpu-2gb-fra1-01 systemd[1]: Started django daemon.
Sep 02 19:44:16 centos-s-1vcpu-2gb-fra1-01 gunicorn[4615]: Error: can't chdir to '/home/user/djangoprojects'
Sep 02 19:44:16 centos-s-1vcpu-2gb-fra1-01 systemd[1]: django.service: Main process exited, code=exited, status=1/FAILURE
Sep 02 19:44:16 centos-s-1vcpu-2gb-fra1-01 systemd[1]: django.service: Failed with result 'exit-code'.

Can someone help me out? I tried a lot of things and researched for a long time, but nothing helped.

Thats the service file:

[Unit]
Description=django daemon
After=network.target

[Service]
User=nginx
Group=nginx
WorkingDirectory=/home/user/djangoprojects/
ExecStart=/usr/local/bin/gunicorn --workers 3 --bind unix:/home/user/djangoprojects/djangoproject.sock djangoproject.wsgi:application

[Install]
WantedBy=multi-user.target


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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @jonasstettner,

From your systemd Unit file and the systemd status log, I think that Nginx cannot access your Django project directory. So make sure that the directory /home/user/djangoprojects actually exists and the nginx account has permission to read it. You can run following command to check:

  1. sudo ls -la /home/user/djangoprojects