By tprzybylek
Hello, I have managed to work through this tutorial, but in the end when I typed my droplet’s IP Adress into the web browser I kept getting the 502 Bad Gateway error.
I checked the nginx error log (sudo tail -30 /var/log/nginx/error.log), and this is the last error:
2018/10/09 08:24:17 [error] 9762#9762: *6 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: 186.46.166.50, server: 46.101.159.58, request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/", host: "46.101.159.58:80"
I figured out that either the gunicorn.socket or gunicorn.service is not running properly, so I ran sudo systemctl status gunicorn.socket and got this result:
● gunicorn.socket - gunicorn socket
Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
Active: active (listening) since Tue 2018-10-09 08:55:34 UTC; 17s ago
Listen: /run/gunicorn.sock (Stream)
CGroup: /system.slice/gunicorn.socket
So the gunicorn.socket is running properly, then I checked the gunicorn.service (sudo systemctl status gunicorn ) and I got this result:
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2018-10-09 09:25:06 UTC; 3s ago
Process: 10224 ExecStart=/my_website/venv/bin/gunicorn -- access-logfile - --workers 3 --bind unix:/run/gunicorn.sock my_website.wsgi:application (code=exited, status=200/CHDIR)
Main PID: 10224 (code=exited, status=200/CHDIR)
Oct 09 09:25:06 ubuntu-s-1vcpu-1gb-fra1-01 systemd[1]: Started gunicorn daemon.
Oct 09 09:25:06 ubuntu-s-1vcpu-1gb-fra1-01 systemd[10224]: gunicorn.service: Changing to the requested working directory failed: No such file or directory
Oct 09 09:25:06 ubuntu-s-1vcpu-1gb-fra1-01 systemd[10224]: gunicorn.service: Failed at step CHDIR spawning /my_website/venv/bin/gunicorn: No such file or directory
Oct 09 09:25:06 ubuntu-s-1vcpu-1gb-fra1-01 systemd[1]: gunicorn.service: Main process exited, code=exited, status=200/CHDIR
Oct 09 09:25:06 ubuntu-s-1vcpu-1gb-fra1-01 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
So it looks like something in my gunicorn.service vonfig file is wrong, but I checked this file and everything looks fine to me. This is my config:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=root
WorkingDirectory=/my_website/
ExecStart=/my_website/venv/bin/gunicorn \
-- access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
my_website.wsgi:application
[Install]
WantedBy=multi-user.target
Anyway, when I change the directory to /my_website/bin/gunicorn and list it’s content it looks like the gunicorn file is there:
root@ubuntu-s-1vcpu-1gb-fra1-01:~/my_website/venv/bin# ls
__pycache__ activate.csh activate_this.py django-admin easy_install **gunicorn** pip pip3.6 python-config python3.6 wagtail
activate activate.fish chardetect django-admin.py easy_install-3.6 gunicorn_paster pip3 python python3 unidecode wheel
But when I run the command " file /my_website/venv/bin/gunicorn", it says that the file is not there.
The question is, how should I define the WorkingDirectory and ExecStart paths? I tried different combinations and none of them seems to work.
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!
I am having same issues and looks like there is no solutions!
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.