Question
connect() failed (111: Connection refused) while connecting to upstream
Hi all,
Everything works - running sudo nginx -t returns:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
However, accessing my domain gives me a 502 Bad Gateway error. Specifically (from /var/log/nginx):
24701#24701: *122588 connect() failed (111: Connection refused) while connecting to upstream, client: 129.213.58.48, server: nativahome.com.ar, request: "GET /dana-na HTTP/1.1", upstream: "http://127.0.0.1:8069/dana-na", host: "161.35.132.215:443" 2020/06/22 10:51:54 [error] 24701#24701: *122590 connect() failed (111: Connection refused) while connecting to upstream, client: 177.207.176.207, server: nativahome.com.ar, request: "GET /dana-na HTTP/1.1", upstream: "http://127.0.0.1:8069/dana-na", host: "161.35.132.215:443" 2020/06/22 10:55:48 [error] 24701#24701: *122593 connect() failed (111: Connection refused) while connecting to upstream, client: 81.196.2.63, server: nativahome.com.ar, request: "GET /dana-na HTTP/1.1", upstream: "http://127.0.0.1:8069/dana-na", host: "161.35.132.215:443" 2020/06/22 11:02:02 [error] 24701#24701: *122597 connect() failed (111: Connection refused) while connecting to upstream, client: 3.80.118.118, server: nativahome.com.ar, request: "GET /jm/jalive HTTP/1.1", upstream: "http://127.0.0.1:8069/jm/jalive", host: "nativahome.com.ar", referrer: "https://www.nativahome.com.ar/jm/jalive" 2020/06/22 11:02:02 [error] 24701#24701: *122597 connect() failed (111: Connection refused) while connecting to upstream, client: 3.80.118.118, server: nativahome.com.ar, request: "GET /jm/jalive HTTP/1.1", upstream: "http://127.0.0.1:8069/jm/jalive", host: "nativahome.com.ar", referrer: "https://www.nativahome.com.ar/jm/jalive"
Here is my /etc/nginx/sites-available
file:
server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name nativahome.com.ar;
location / {
proxy_pass http://localhost:8069;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/nativahome.com.ar/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/nativahome.com.ar/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = nativahome.com.ar) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name nativahome.com.ar;
return 404; # managed by Certbot
}
server {
server_name www.nativahome.com.ar;
return 301 https://nativahome.com.ar$request_uri;
}
my netstat -plant
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 25890/postgres
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 24701/nginx: worker
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 24701/nginx: worker
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 3159/systemd-resolv
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1013/sshd
tcp 0 464 161.35.132.215:22 138.121.113.235:28822 ESTABLISHED 6704/sshd: root@pts
tcp6 0 0 :::443 :::* LISTEN 24701/nginx: worker
tcp6 0 0 :::80 :::* LISTEN 24701/nginx: worker
tcp6 0 0 :::22 :::* LISTEN 1013/sshd
Any ideas?
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.
×