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

Posted September 2, 2020 1.6k views

I was following this tutorial: 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:

Description=django daemon

ExecStart=/usr/local/bin/gunicorn --workers 3 --bind unix:/home/user/djangoprojects/djangoproject.sock djangoproject.wsgi:application


edited by MattIPv4

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.

Submit an Answer
1 answer

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:

  • sudo ls -la /home/user/djangoprojects