I keep getting a 502 Bad Gateway each time I try to access my web app. It was accessible prior but suddenly started showing a 502 Bad Gateway. My nginx configuration is
server {
listen 80;
server_name IP_ADDRESS;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/user/pyapps/test_project;
}
location /media/ {
root /home/user/pyapps/test_project;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
Gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=user
Group=www-data
WorkingDirectory=/home/user/pyapps/test_project
ExecStart=/home/user/pyapps/venv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
test.wsgi:application
[Install]
WantedBy=multi-user.target
sudo systemctl status gunicorn.socket gives:
● gunicorn.socket - gunicorn socket
Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
Active: failed (Result: service-start-limit-hit) since Thu 2023-03-30 06:50:20 UTC; 18min ago
Triggers: ● gunicorn.service
Listen: /run/gunicorn.sock (Stream)
Mar 30 06:46:29 ... systemd[1]: Listening on gunicorn socket.
Mar 30 06:50:20 ... systemd[1]: gunicorn.socket
sudo systemctl status gunicorn.service gives:
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service_; disabled; vendor preset: enabled)_
Active: failed (Result: exit-code) since Thu 2023-03-30 06:50:20 UTC_; 21min ago_
TriggeredBy: ● gunicorn.socket
Process: 46876 ExecStart=/home/.../pyapps/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock ccpfew.wsgi:application (code=exited, status=203/EXEC)
Main PID: 46876 (code=exited, status=203/EXEC)
Mar 30 06:50:20 ... systemd[1]: Started gunicorn daemon.
Mar 30 06:50:20 ... systemd[46876]: gunicorn.service: Failed to execute command: No such file or directory
Mar 30 06:50:20 ... systemd[46876]: gunicorn.service: Failed at step EXEC spawning /home/.../pyapps/venv/bin/gunicorn: No such file or directory
Mar 30 06:50:20 ... systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Mar 30 06:50:20 ... systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Mar 30 06:50:20 ... systemd[1]: gunicorn.service: Start request repeated too quickly.
Mar 30 06:50:20 ... systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Mar 30 06:50:20 ... systemd[1]: Failed to start gunicorn daemon.
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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hi there,
As far as I can see, it looks like that the
gunicorn
executable cannot be found, as indicated by the error message:Can you confirm if you’ve followed the Creating a Python Virtual Environment for your Project step from the Django setup tutorial?
Besides that, the Nginx configuration file and the service file look correct.
Best,
Bobby