Django runs on pm2 but nginx fails to start
We are running Django app using PM2 with following script:
apps:
[{
name: "app_name",
script: "manage.py",
args: ["runserver", "127.0.0.1:8000"],
exec_mode: "fork",
instances: "1",
wait_ready: true,
autorestart: false,
max_restarts: 5,
interpreter : "python3"
}]
}
And we expect nginx to tunnel it to world. While nginx -t results ok but nginx fails to start.
Following is the nginx configuration:
upstream app_server {
server unix:/home/django/gunicorn.socket fail_timeout=0;
}
server {
listen 8000 default_server;
listen [::]:8000 default_server;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/app_name/app_name/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/app_name/app_name/static;
}
# Proxy the static assests for the Django Admin panel
# Warning! This location is highly sensitive to how django is installed sys>
location /static/admin {
alias /usr/local/lib/python3.8/dist-packages/django/contrib/admin/static>
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://127.0.0.1:8000/;
}
}
When we restart nginx with: sudo service nginx restart
We get control process exited with error code. After debugging with journalctl -xe
we get:
The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Failed to start A high performance web server and a reverse proxy server.
What could be going wrong?