502 Bad Gateway error on nginx

Details:

Nextcloud version (eg, 20.0.5): 23.0.0.0
Operating system and version (eg, Ubuntu 20.04): Debian 11
Apache or nginx version (eg, Apache 2.4.25): nginx 1.23.1
PHP version (eg, 7.4): 7.4

The issue you are facing:

I’m hosting a main domain (call it example.com) on my Debian 11 VPS running nginx. I have two subdomains under this domain, each intended for a different service: the first (searx.example.com) is running a SearX instance. This works as intended.

However, my Nextcloud subdomain (nextcloud.example.com) returns a 502 Bad Gateway error.

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Go to nextcloud.example.com
  2. See error

The output of your Nextcloud log in Admin > Logging:
Can’t access log, as no GUI due to 502.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

There is no config.php file at /var/www/nextcloud. However, there is a directory /var/www/nextcloud/config that contains a file named config.sample.php.

The output of your Apache/nginx/system log in /var/log/____:

Here is the latest access.log:

1.2.3.4 - - [07/Sep/2022:23:01:04 +0000] "POST /search HTTP/2.0" 200 23597 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36" "-"
1.2.3.4 - - [07/Sep/2022:23:01:43 +0000] "GET / HTTP/2.0" 502 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36" "-"
1.2.3.4 - - [07/Sep/2022:23:03:13 +0000] "GET / HTTP/2.0" 502 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36" "-"
1.2.3.4 - - [07/Sep/2022:23:03:21 +0000] "GET / HTTP/2.0" 502 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36" "-"
1.2.3.4 - - [07/Sep/2022:23:03:39 +0000] "GET / HTTP/2.0" 502 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36" "-"
1.2.3.4 - - [07/Sep/2022:23:03:46 +0000] "GET / HTTP/2.0" 502 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36" "-"
1.2.3.4 - - [07/Sep/2022:23:03:47 +0000] "GET / HTTP/2.0" 502 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36" "-"
1.2.3.4 - - [07/Sep/2022:23:03:48 +0000] "GET / HTTP/2.0" 502 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36" "-"

And here is the latest error.log:

2022/09/07 22:56:31 [error] 64674#64674: *22 connect() failed (111: Connection refused) while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 22:56:31 [warn] 64674#64674: *22 upstream server temporarily disabled while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 23:01:43 [error] 64674#64674: *29 connect() failed (111: Connection refused) while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 23:01:43 [warn] 64674#64674: *29 upstream server temporarily disabled while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 23:01:43 [crit] 64674#64674: *29 connect() to unix:/var/run/php/php7.4-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "nextcloud.example.com"
2022/09/07 23:01:43 [warn] 64674#64674: *29 upstream server temporarily disabled while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "nextcloud.example.com"
2022/09/07 23:03:13 [error] 64674#64674: *32 connect() failed (111: Connection refused) while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 23:03:13 [warn] 64674#64674: *32 upstream server temporarily disabled while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 23:03:13 [crit] 64674#64674: *32 connect() to unix:/var/run/php/php7.4-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "nextcloud.example.com"
2022/09/07 23:03:13 [warn] 64674#64674: *32 upstream server temporarily disabled while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "nextcloud.example.com"
2022/09/07 23:03:21 [error] 64674#64674: *32 no live upstreams while connecting to upstream, client: 1.2.3.4, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://php-handler", host: "nextcloud.example.com"
2022/09/07 23:03:39 [error] 64674#64674: *35 connect() failed (111: Connection refused) while connecting to upstream, client: 2.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 23:03:39 [warn] 64674#64674: *35 upstream server temporarily disabled while connecting to upstream, client: 2.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 23:03:39 [crit] 64674#64674: *35 connect() to unix:/var/run/php/php7.4-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 2.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "nextcloud.example.com"
2022/09/07 23:03:39 [warn] 64674#64674: *35 upstream server temporarily disabled while connecting to upstream, client: 2.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "nextcloud.example.com"
2022/09/07 23:03:46 [error] 64674#64674: *35 no live upstreams while connecting to upstream, client: 2.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://php-handler", host: "nextcloud.example.com"
2022/09/07 23:03:47 [error] 64674#64674: *35 no live upstreams while connecting to upstream, client: 2.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://php-handler", host: "nextcloud.example.com"
2022/09/07 23:03:48 [error] 64674#64674: *35 no live upstreams while connecting to upstream, client: 2.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://php-handler", host: "nextcloud.example.com"
2022/09/07 23:13:19 [error] 64674#64674: *49 connect() failed (111: Connection refused) while connecting to upstream, client: 1.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 23:13:19 [warn] 64674#64674: *49 upstream server temporarily disabled while connecting to upstream, client: 1.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "nextcloud.example.com"
2022/09/07 23:13:19 [crit] 64674#64674: *49 connect() to unix:/var/run/php/php7.4-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 1.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "nextcloud.example.com"
2022/09/07 23:13:19 [warn] 64674#64674: *49 upstream server temporarily disabled while connecting to upstream, client: 1.3.5.7, server: nextcloud.example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "nextcloud.example.com"

Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

As above, no .log file in /var/www/nextcloud/.

Additionally, here’s my config file for the nextcloud subdomain, and here’s the default conf file of nginx itself.

And if it helps, here’s the config file of the perfectly functional SearX subdomain.

Important note: As I’m running a Debian 11 VPS, the nginx install initially didn’t have sites-available and sites-enabled directories under /etc/nginx/. Instead, it’s initial config file default was under /etc/nginx/conf.d.

I changed this setup by creating sites-available and sites-enabled directories, moving the default config file from conf.d to sites-available, and creating a symlink between the copied file and sites-enabled. I hope this context helps.