By mjin1
I just create a new data table in Django app and then I sudo reboot it. I got 502 Bad gat way errors.
sudo tail -30 /var/log/nginx/error.log
Here is the error code I find out:
2021/09/23 20:17:51 [crit] 983#983: *11 connect() to unix:/run/gunicorn/socket failed (2: No such file or directory) while connecting to upstream, client: 100.15.117.115, server: sg-weather.com, request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn/socket:/", host: "sg-weather.com"
Here is what I tried:
sudo nginx -t
systemctl status nginx
Output:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-09-23 19:57:39 UTC; 22min ago
Docs: man:nginx(8)
Process: 977 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 935 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 982 (nginx)
Tasks: 3 (limit: 2360)
CGroup: /system.slice/nginx.service
├─982 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─983 nginx: worker process
└─984 nginx: worker process
sudo systemctl daemon-reload
sudo systemctl start gunicorn
sudo systemctl enable gunicorn
sudo systemctl restart nginx
which gunicorn
Output: /usr/bin/gunicorn
Then I go to /etc/systemd/system/gunicorn.service and find out the following text:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
PIDFile=/run/gunicorn/pid
User=shane
Group=www-data
RuntimeDirectory=gunicorn
WorkingDirectory=/home/shane/springgem
ExecStart=/home/shane/springgem/springgem_env/bin/gunicorn\1
--access-logfile - \
--pid /run/gunicorn/pid \
--workers 3 \
--env DJANGO_SETTINGS_MODULE=springgem.settings \
--bind unix:/run/gunicorn/socket \
--pythonpath '/home/shane/springgem,/home/shane/springgem/coronavirus_tracker' \
--chdir '/home/shane/springgem' \
springgem.wsgi:application
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
I realize the ExecStart path is different so I change to the path that generate from which gunicorn. And run following commands. But it still not working.
sudo systemctl daemon-reload
sudo systemctl restart gunicorn
Thanks for any help!
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!
Hello,
Nginx seems to be working as expected, this looks like a problem with the Gunicorn service as you are getting the following error:
connect() to unix:/run/gunicorn.sock failed (2: No such file or directory)
This indicates that Nginx was unable to find the gunicorn.sock file at the given location.
You should compare the proxy_pass location defined within /etc/nginx/sites-available/your_project file to the actual location of the gunicorn.sock file generated by the gunicorn.socket systemd unit.
If you cannot find a gunicorn.sock file within the /run directory, it generally means that the systemd socket file was unable to create it. For this I would recommend going through the section on checking for the Gunicorn socket file to step through the troubleshooting steps for Gunicorn from this tutorial here:
Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.