Hi everyone,

I’m getting a 502 Bad Gateway to my django project.

Everything was working until i directed my domain name to my ip adress. Can anyone help?

local_settings.py
SECRET_KEY = 'n'
ALLOWED_HOSTS = ['159.65.235.171','.petergitz.com','.www.petergitz.com']
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME':'portfoliodb',
        'USER':'dbuser',
        'PASSWORD':'####',
        'HOST':'localhost',
        'PORT':'5432',
    }
}
/etc/systemd/system/gunicorn.socket

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target
/etc/systemd/system/gunicorn.service

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

[Service]
User=peter
Group=www-data
WorkingDirectory=/home/peter/portfolio-project
ExecStart=/home/peter/myenv/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          portfolio.wsgi:application

[Install]
WantedBy=multi-user.target
gunicorn status
● gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2020-04-05 13:14:41 UTC; 23h ago
 Main PID: 1184 (code=exited, status=1/FAILURE)

Apr 05 13:14:36 portfolio systemd[1]: Started gunicorn daemon.
Apr 05 13:14:36 portfolio gunicorn[1184]: [2020-04-05 13:14:36 +0000] [1184] [INFO] Starting gunicorn 20.0.4
Apr 05 13:14:36 portfolio gunicorn[1184]: [2020-04-05 13:14:36 +0000] [1184] [ERROR] Retrying in 1 second.
Apr 05 13:14:37 portfolio gunicorn[1184]: [2020-04-05 13:14:37 +0000] [1184] [ERROR] Retrying in 1 second.
Apr 05 13:14:38 portfolio gunicorn[1184]: [2020-04-05 13:14:38 +0000] [1184] [ERROR] Retrying in 1 second.
Apr 05 13:14:39 portfolio gunicorn[1184]: [2020-04-05 13:14:39 +0000] [1184] [ERROR] Retrying in 1 second.
Apr 05 13:14:40 portfolio gunicorn[1184]: [2020-04-05 13:14:40 +0000] [1184] [ERROR] Retrying in 1 second.
Apr 05 13:14:41 portfolio gunicorn[1184]: [2020-04-05 13:14:41 +0000] [1184] [ERROR] Can't connect to /run/gunicorn.sock
Apr 05 13:14:41 portfolio systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
Apr 05 13:14:41 portfolio systemd[1]: gunicorn.service: Failed with result 'exit-code'.
/etc/nginx/sites-available/portfolio

server {
    listen 80;
    server_name  159.65.235.171 petergitz.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/peter/portfolio-project;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}
sudo tail -F /var/log/nginx/error.log
2020/04/06 11:49:47 [error] 20452#20452: *5 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: 104.128.63.109, server: 159.65.235.171, request: "GET /cms/wp-includes/wlwmanifest.xml HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/cms/wp-includes/wlwmanifest.xml", host: "petergitz.com"
2020/04/06 12:18:46 [error] 20452#20452: *17 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: 150.107.138.37, server: 159.65.235.171, request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/", host: "159.65.235.171:80"
2020/04/06 12:47:32 [error] 20452#20452: *19 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: 41.205.25.203, server: 159.65.235.171, request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/", host: "159.65.235.171:80"
edited by MattIPv4
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!