Question

502 error on django application after server reboot

Posted February 2, 2021 727 views
DjangoPython FrameworksDigitalOcean App Platform

this is my gunicorn.service file.

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myprojectdir
ExecStart=/var/www/html/new_remove_bg/newvenv/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          /var/www/html/new_remove_bg/mysite/mysite.wsgi:application

[Install]
WantedBy=multi-user.target




ExecStart=/var/www/html/new_remove_bg/newvenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/var/www/html/new_remove_bg/mysite/mysite.sock myproject.wsgi:application

this is my newremovebg file

server {
    listen 80;
    server_name slicebg.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /var/www/html/new_remove_bg/mysite;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/var/www/html/new_remove_bg/mysite/mysite.sock;
    }
}

Please guide me how to overcome this issue and i am trying to deploy django application.

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
2 answers

Hi there,

You would see a 502 error when the backend service is not running.

Is the Gunicorn service running? You can check that with this command:

sudo systemctl status gunicorn

If it is not running make sure that it is started:

sudo systemctl start gunicorn

Also you can enable the service, so that the next time the server reboots, it would start automatically:

sudo systemctl enable gunicorn

Let me know how it goes.
Regards,
Bobby

Show answer This answer has been marked as resolved by attam059.