Gateway Error 502 On Recently Updated Server

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Hello, I recently updated to the newest version of Nextcloud and after completing a safe restart of the server to install more storage it seems i’m having a gateway error 502 on my domain, Its routed via cloudflare tunnels and it was working before and it shows it still running, I’ve disabled all non necessary features on it to check if it was that but it seems to still be having the same issue, I’ve double checked and it is running as its showing the non trusted domain on the servers local IP.

Nextcloud version (eg, 20.0.5): 27.1.0.7
Operating system and version (eg, Ubuntu 20.04): Debian 12
Apache or nginx version (eg, Apache 2.4.25): 2.4.56
PHP version (eg, 7.4): 8.1.17

The issue you are facing:

Gateway error 502

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

Steps to replicate it:

  1. Open domain

The output of your Nextcloud log in Admin > Logging:

Unable As Cant Access GUI

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

<?php
$CONFIG = array (
  'passwordsalt' => '**REMOVED**',
  'secret' => '**REMOVED**',
  'trusted_domains' => 
  array (
    0 => '**REMOVED**',
  ),
  'trusted_proxies' => ['**REMOVED**'],
  'datadirectory' => '/var/www/nextcloud-data',
  'dbtype' => 'mysql',
  'version' => '27.1.0.7',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '**REMOVED**',
  'installed' => true,
  'instanceid' => '**REMOVED**',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
  ),
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'updater.secret' => '**REMOVED**',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
);

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

Mon Sep 18 22:08:09.572927 2023] [ssl:warn] [pid 513] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:08:09.572990 2023] [ssl:error] [pid 513] AH02217: ssl_stapling_init_cert: can't retrieve issuer certificate! [subject: CN=nextcloud / issue>
[Mon Sep 18 22:08:09.572994 2023] [ssl:error] [pid 513] AH02604: Unable to configure certificate localhost:443:0 for stapling
[Mon Sep 18 22:08:09.573117 2023] [ssl:warn] [pid 513] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:08:09.573149 2023] [ssl:error] [pid 513] AH02217: ssl_stapling_init_cert: can't retrieve issuer certificate! [subject: CN=tkldev / issuer: >
[Mon Sep 18 22:08:09.573158 2023] [ssl:error] [pid 513] AH02604: Unable to configure certificate localhost:443:0 for stapling
[Mon Sep 18 22:08:09.573441 2023] [ssl:warn] [pid 513] AH01909: localhost:12322:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:08:09.573526 2023] [mpm_prefork:notice] [pid 513] AH00163: Apache/2.4.56 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Mon Sep 18 22:08:09.573530 2023] [core:notice] [pid 513] AH00094: Command line: '/usr/sbin/apache2'
[Mon Sep 18 22:11:32.026833 2023] [mpm_prefork:notice] [pid 513] AH00171: Graceful restart requested, doing restart
[Mon Sep 18 22:11:32.058086 2023] [ssl:warn] [pid 513] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:11:32.058151 2023] [ssl:error] [pid 513] AH02217: ssl_stapling_init_cert: can't retrieve issuer certificate! [subject: CN=nextcloud / issue>
[Mon Sep 18 22:11:32.058155 2023] [ssl:error] [pid 513] AH02604: Unable to configure certificate localhost:443:0 for stapling
[Mon Sep 18 22:11:32.058290 2023] [ssl:warn] [pid 513] AH01909: localhost:12322:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:11:32.058376 2023] [mpm_prefork:notice] [pid 513] AH00163: Apache/2.4.56 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Mon Sep 18 22:11:32.058380 2023] [core:notice] [pid 513] AH00094: Command line: '/usr/sbin/apache2'
[Mon Sep 18 22:15:32.945021 2023] [mpm_prefork:notice] [pid 513] AH00170: caught SIGWINCH, shutting down gracefully
[Mon Sep 18 22:15:43.739637 2023] [ssl:warn] [pid 240] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:15:43.785524 2023] [ssl:error] [pid 240] AH02217: ssl_stapling_init_cert: can't retrieve issuer certificate! [subject: CN=nextcloud / issue>
[Mon Sep 18 22:15:43.785534 2023] [ssl:error] [pid 240] AH02604: Unable to configure certificate localhost:443:0 for stapling
[Mon Sep 18 22:15:43.785696 2023] [ssl:warn] [pid 240] AH01909: localhost:12322:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:15:49.958896 2023] [ssl:warn] [pid 488] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:15:49.958971 2023] [ssl:error] [pid 488] AH02217: ssl_stapling_init_cert: can't retrieve issuer certificate! [subject: CN=nextcloud / issue>
[Mon Sep 18 22:15:49.958976 2023] [ssl:error] [pid 488] AH02604: Unable to configure certificate localhost:443:0 for stapling
[Mon Sep 18 22:15:49.959111 2023] [ssl:warn] [pid 488] AH01909: localhost:12322:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:15:49.963315 2023] [mpm_prefork:notice] [pid 488] AH00163: Apache/2.4.56 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Mon Sep 18 22:15:49.963328 2023] [core:notice] [pid 488] AH00094: Command line: '/usr/sbin/apache2'
[Mon Sep 18 22:23:42.314872 2023] [mpm_prefork:notice] [pid 488] AH00171: Graceful restart requested, doing restart
[Mon Sep 18 22:23:42.842094 2023] [ssl:warn] [pid 488] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:23:42.842162 2023] [ssl:error] [pid 488] AH02217: ssl_stapling_init_cert: can't retrieve issuer certificate! [subject: CN=nextcloud / issue>
[Mon Sep 18 22:23:42.842174 2023] [ssl:error] [pid 488] AH02604: Unable to configure certificate localhost:443:0 for stapling
[Mon Sep 18 22:23:42.842311 2023] [ssl:warn] [pid 488] AH01909: localhost:12322:0 server certificate does NOT include an ID which matches the server name
[Mon Sep 18 22:23:42.842406 2023] [mpm_prefork:notice] [pid 488] AH00163: Apache/2.4.56 (Debian) OpenSSL/1.1.1n configured -- resuming normal operations
[Mon Sep 18 22:23:42.842410 2023] [core:notice] [pid 488] AH00094: Command line: '/usr/sbin/apache2'

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.

No Error only successful updates 

Seems as if you have a similar problem to this one

apache 2.4 - Problems with SSL: Unable to configure certificate for slaping - Server Fault

What if you - for test purposes - turn the SSL stapling on to off and try whith that?

Further info for the OCSP Stapling
https://www.digitalocean.com/community/tutorials/how-to-configure-ocsp-stapling-on-apache-and-nginx

In my config the line

'overwrite.cli.url' => 'http://localhost',

is

'overwrite.cli.url' => 'https://MY.PUBLIC.DOMAIN.NAME',

e,g,

'overwrite.cli.url' => 'https://my.nextcloud.com',

related to
https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#default-config-php-examples

and in my config the part for the trusted domains is …

  'trusted_domains' => 
  array (
    0 => 'local-IPv4-Address of the NC Server',
    1 => 'MY.PUBLIC.DOMAIN.NAME',
  ),

Hi, Thanks for the quick reply, I tried changing the config using the ones u sent and double checked it has the correct syntax using apaches syntax checker and it said all good, I also disabled ssl stapling but im still sadly having the issue (Please see included new configs etc)

ue Sep 19 15:27:46.927381 2023] [ssl:warn] [pid 419] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Tue Sep 19 15:27:46.927568 2023] [ssl:warn] [pid 419] AH01909: localhost:12322:0 server certificate does NOT include an ID which matches the server name
[Tue Sep 19 15:27:46.927655 2023] [mpm_prefork:notice] [pid 419] AH00163: Apache/2.4.56 (Debian) OpenSSL/1.1.1n configured – resuming normal operations
[Tue Sep 19 15:27:46.927659 2023] [core:notice] [pid 419] AH00094: Command line: ‘/usr/sbin/apache2’

<?php $CONFIG = array ( 'passwordsalt' => '**REMOVED**', 'secret' => '**REMOVED**', 'trusted_domains' => array ( 0 => '192.168.1.17', 0 => 'nextcloud.**REMOVED**.co.uk', ), 'trusted_proxies' => array ( 0 => '192.168.1.17', 1 => 'nextcloud.**REMOVED**.co.uk', ), 'datadirectory' => '/var/www/nextcloud-data', 'dbtype' => 'mysql', 'version' => '27.1.0.7', 'overwrite.cli.url' => 'https://nextcloud.**REMOVED**.co.uk', 'dbname' => 'nextcloud', 'dbhost' => 'localhost', 'dbport' => '', 'dbtableprefix' => 'oc_', 'mysql.utf8mb4' => true, 'dbuser' => 'nextcloud', 'dbpassword' => '**REMOVED**', 'installed' => true, 'instanceid' => '**REMOVED**', 'memcache.local' => '\\OC\\Memcache\\Redis', 'redis' => array ( 'host' => '/var/run/redis/redis.sock', 'port' => 0, 'timeout' => 0.0, ), 'filelocking.enabled' => true, 'memcache.locking' => '\\OC\\Memcache\\Redis', 'updater.secret' => '**REMOVED**', 'maintenance' => false, 'theme' => '', 'loglevel' => 2, );

i don’t know which server certificate you use but it can’t be “localhost”.
Is it a let’s encrypt cert?

Then you should give the config your real “public” server name to connect to your NC Server.