Score:0

Fix 502 Bad Gateway

in flag

I have Nginx running on Ubuntu server (digital ocean), I've setup LEMP stack for hosting the Wordpress website. I'm getting 501 Bad Gateway when I try to reach website using the IP address.

I see this errors in the log:

2022/05/24 14:43:52 [error] 199802#199802: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 212.58.120.29, server: localhost, request: "GET /ttemp.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "46.101.238.240"
2022/05/24 14:43:52 [error] 199802#199802: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 212.58.120.29, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "46.101.238.240", referrer: "https://46.101.238.240/ttemp.php"

And here's my Nginx config:

server {
    listen       80;
    listen       443 ssl;
    ssl_certificate /var/www/ssl/default.crt;
    ssl_certificate_key /var/www/ssl/default.key;
    server_name localhost mydomain.com www.mydomain.com;

    root /var/www/mydomain.com;

    error_log /var/log/nginx/error.log info;

    location / {
        try_files $uri $uri/ /index.php?$args;
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

}

And my UFW status:

To                         Action      From
--                         ------      ----
Nginx HTTP                 ALLOW       Anywhere
Nginx HTTPS                ALLOW       Anywhere
22/tcp                     ALLOW       Anywhere
22                         ALLOW       Anywhere
2222                       ALLOW       Anywhere
3306                       ALLOW       Anywhere
80                         ALLOW       Anywhere
443                        ALLOW       Anywhere
9000                       ALLOW       Anywhere
Nginx HTTP (v6)            ALLOW       Anywhere (v6)
Nginx HTTPS (v6)           ALLOW       Anywhere (v6)
22/tcp (v6)                ALLOW       Anywhere (v6)
22 (v6)                    ALLOW       Anywhere (v6)
2222 (v6)                  ALLOW       Anywhere (v6)
3306 (v6)                  ALLOW       Anywhere (v6)
80 (v6)                    ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)
9000 (v6)                  ALLOW       Anywhere (v6)

Any ideas?

Ivan Shatsky avatar
gr flag
Show the `lsof -P -n -i :9000` output, please.
in flag
`lsof -P -n -i :9000` command gives no output
Ivan Shatsky avatar
gr flag
That means the PHP-FPM daemon doesn't listen TCP port 9000. Check the default pool configuration, most likely it is listen on some UNIX socket instead.
in flag
@IvanShatsky it helped, thanks a lot!
djdomi avatar
za flag
please answer the questions else it will stay open forever.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.