0

I have developed a web application with Django and I am trying to publish it in a virtual machine created with Azure. To do that I'm using the following software stack:

  • Ubuntu (20.04)
  • Django (3.0.7)
  • Virtualenv (20.0.17)
  • Gunicorn (20.1.0)
  • Nginx (1.18.0)

To deploy the app I followed that guide: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

My django project folders are organized as follows:

home/
├─ useradmin/
│  ├─ myproject/
│  │  ├─ proj/
│  │  │  ├─ settings.py
│  │  │  ├─ urls.py
│  │  │  ├─ wsgi.py
│  │  │  ├─ ...
│  │  ├─ static/
│  │  ├─ templates/
│  │  ├─ venv/
│  │  ├─ manage.py
│  │  ├─ ...

This is my /etc/systemd/system/gunicorn.service:

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

[Service]
User=useradmin
Group=www-data
WorkingDirectory=/home/useradmin/myproject
ExecStart=/home/useradmin/myproject/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/useradmin/myproject/myproject.sock proj.wsgi:application
[Install]
WantedBy=multi-user.target

This is my /etc/nginx/sites-available/myproject:

server {
    listen 80;
    server_name mydomain.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/useradmin/myproject;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/useradmin/myproject/myproject.sock;
    }
}

When I navigate to mydomain.com I get a 502 Bad Gateway error. If I check the Nginx logs by running "sudo tail -F /var/log/nginx/error.log" I see the following error:

2022/03/16 08:27:33 [crit] 64480#64480: *3 connect() to unix:/home/useradmin/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XX, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/useradmin/myproject/myproject.sock:/", host: "mydomain.com"

To create the sock file I run the following instructions but nothing changes:

systemctl daemon-reload
systemctl restart gunicorn.service

UPDATE 1:

Trying to execute the instruction ls -la /home/useradmin/myproject/myproject.sock I get the error ls: cannot access '/home/useradmin/myproject/myproject.sock': No such file or directory

El_Merendero
  • 111
  • 3
  • what does `ls -la /home/useradmin/myproject/myproject.sock` shows? and afaik it might a easier issue - please try http://unix:/home/useradmin/myproject/myproject.sock: ; – djdomi Mar 16 '22 at 09:05
  • It returns `ls: cannot access '/home/useradmin/myproject/myproject.sock': No such file or directory` – El_Merendero Mar 16 '22 at 09:07
  • fix your unicorn service at first and second please dont post comments with your informations, edit the question and add the information there – djdomi Mar 16 '22 at 09:09
  • Ok very thanks, I'm editing the question. How can I fix the unicorn service? – El_Merendero Mar 16 '22 at 09:11
  • ```ExecStart='/home/useradmin/myproject/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/useradmin/myproject/myproject.sock proj.wsgi:application' ``` may be the issue... BEcause it States ``` gunicorn: error: argument -b/--bind: expected one argument ``` and you provide 2 arguments not one. And a Minus-Symbol that i dont understand for what it should be – djdomi Mar 16 '22 at 09:31

0 Answers0