Bad gateway - Error code 502

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

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:

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • AIO v12.7.0
  • Operating system and version (e.g., Ubuntu 24.04):
    • Debian 12.13
  • Web server and version (e.g, Apache 2.4.25):
    • NA
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • Using Cloudflare Tunnel
  • PHP version (e.g, 8.3):
    • NA
  • Is this the first time you’ve seen this error? (Yes / No):
    • Yes
  • When did this problem seem to first start?
    • 1 Jan 2026
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • AIO
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • Using Cloudflare Tunnel

Summary of the issue you are facing:

Suspect misconfiguration on my setup, because the bad gateway error does not happen on a newly created AIO instance, where I reset (based on this guide) and installed the new instance with the same domain name and compose file without restoring my backup. However, I cannot figure out what went wrong as I didn’t do any configuration.

*Disabling my UFW firewall and adding APACHE_IP_BINDING: 127.0.0.1 in the compose file below (It was working fine previously without setting APACHE_IP_BINDING) doesn’t help
*I launched my compose file below (nextcloud-aio-mastercontainer) via Portainer CE 2.33.7 LTS

Appreciate any guidance to debug this sudden issue.

Steps to replicate it (hint: details matter!):

Not applicable, as the issue was discovered only when I access my nextcloud website. I did not configure anything.

Log entries

Nextcloud

Please provide the log entries from your Nextcloud log that are generated during the time of problem (via the Copy raw option from Administration settings->Logging screen or from your nextcloud.log located in your data directory). Feel free to use a pastebin/gist service if necessary.

*Below is copied from nextcloud-aio-nextcloud container log

Connection to nextcloud-aio-database (172.19.0.5) 5432 port [tcp/postgresql] succeeded!
              now              
-------------------------------
 2026-02-18 22:15:40.541602+08
(1 row)
+ '[' -f /dev-dri-group-was-added ']'
++ find /dev -maxdepth 1 -mindepth 1 -name dri
+ '[' -n '' ']'
+ set +x
Connection to nextcloud-aio-redis (172.19.0.6) 6379 port [tcp/redis] succeeded!
Updated data-fingerprint to <hidden>
Scanning AppData for files
	Folder /appdata_ocidm99ao9ld/preview
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 1       | 0     | 00:00:29     |
+---------+-------+--------------+
Applying one-click-instance settings...
System config value one-click-instance set to boolean true
System config value one-click-instance.user-limit set to integer 100
System config value one-click-instance.link set to string https://nextcloud.com/all-in-one/
support already enabled
Adjusting log files...
System config value upgrade.cli-upgrade-link set to string https://github.com/nextcloud/all-in-one/discussions/2726
System config value logfile set to string /var/www/html/data/nextcloud.log
Config value were not updated
System config value updatedirectory set to string /nc-updater
System config value maintenance_window_start set to integer 100
Applying network settings...
System config value allow_local_remote_servers set to boolean true
System config value davstorage.request_timeout set to integer 7200
System config value trusted_domains => 1 set to string <my-custom-domain>.com
System config value overwrite.cli.url set to string https://<my-custom-domain>.com/
System config value documentation_url.server_logs set to string https://github.com/nextcloud/all-in-one/discussions/5425
System config value htaccess.RewriteBase set to string /
.htaccess has been updated
System config value dbpersistent set to boolean false
System config value auth.bruteforce.protection.enabled set to boolean true
System config value ratelimit.protection.enabled set to boolean true
System config value files_external_allow_create_new_local set to boolean false
System config value trusted_proxies => 0 set to string 127.0.0.1
System config value trusted_proxies => 1 set to string ::1
System config value trusted_proxies => 10 set to string 172.19.0.0/16
Config value were not updated
+ echo nextcloud-aio-collabora
+ grep -q 'nextcloud-.*-collabora'
+ COLLABORA_HOST=<my-custom-domain>.com
+ set +x
Config value 'wopi_url' for app 'richdocuments' is now set to 'https://<my-custom-domain>.com/', stored as mixed in fast cache
Config value were not updated
System config value enabledPreviewProviders => 0 set to string OC\Preview\Imaginary
System config value enabledPreviewProviders => 23 set to string OC\Preview\ImaginaryPDF
System config value preview_imaginary_url set to string http://nextcloud-aio-imaginary:9000
System config value preview_imaginary_key set to string <hidden>
+ '[' true = true ']'
+ '[' 11000 = 443 ']'
+ set +x
Waiting for nextcloud-aio-apache to become available...
[18-Feb-2026 22:16:29] NOTICE: fpm is running, pid 208
[18-Feb-2026 22:16:29] NOTICE: ready to handle connections
Connection to nextcloud-aio-apache (172.19.0.9) 11000 port [tcp/*] succeeded!
Activating Collabora config...
✓ Set WOPI url to http://nextcloud-aio-apache:23973
✓ Set callback url to http://nextcloud-aio-apache:23973
Checking configuration
🛈 Configured WOPI URL: http://nextcloud-aio-apache:23973
🛈 Configured public WOPI URL: https://<my-custom-domain>.com
🛈 Configured callback URL: http://nextcloud-aio-apache:23973
✓ Fetched /hosting/discovery endpoint
✓ Valid mimetype response
✓ Valid capabilities entry
✓ Fetched /hosting/capabilities endpoint
✓ Detected WOPI server: Collabora Online Development Edition 25.04.8.3
Collabora URL (used for Nextcloud to contact the Collabora server):
  http://nextcloud-aio-apache:23973
Collabora public URL (used in the browser to open Collabora):
  https://<my-custom-domain>.com
Callback URL (used by Collabora to connect back to Nextcloud):
  http://nextcloud-aio-apache:23973

Web Browser

If the problem is related to the Web interface, open your browser inspector Console and Network tabs while refreshing (reloading) and reproducing the problem. Provide any relevant output/errors here that appear.

PASTE

Web server / Reverse Proxy

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

*Below is copied from nextcloud-aio-apache container log.

Waiting for Nextcloud to start...
Waiting for Nextcloud to start...
Waiting for Nextcloud to start...
Waiting for Nextcloud to start...
Waiting for Nextcloud to start...
Connection to nextcloud-aio-nextcloud (172.19.0.8) 9000 port [tcp/*] succeeded!
[Wed Feb 18 22:16:34.762759 2026] [mpm_event:notice] [pid 41:tid 41] AH00489: Apache/2.4.66 (Unix) configured -- resuming normal operations
[Wed Feb 18 22:16:34.762904 2026] [core:notice] [pid 41:tid 41] AH00094: Command line: '/usr/local/apache2/bin/httpd -D FOREGROUND'
INF INF INF INF INF INF INF INF ts=1771424194.7900217 INF INF INF INF INF INF INF INF ts=1771424194.7900217 msg=maxprocs: Leaving GOMAXPROCS=4: CPU quota undefined
INF INF INF INF INF INF INF INF ts=1771424194.790443 INF INF INF INF INF INF INF INF ts=1771424194.790443 msg=GOMEMLIMIT is updated INF INF INF INF INF INF INF INF ts=1771424194.790443 INF INF INF INF INF INF INF INF ts=1771424194.790443 msg=GOMEMLIMIT is updated package=github.com/KimMachineGun/automemlimit/memlimit INF INF INF INF INF INF INF INF ts=1771424194.790443 INF INF INF INF INF INF INF INF ts=1771424194.790443 msg=GOMEMLIMIT is updated INF INF INF INF INF INF INF INF ts=1771424194.790443 INF INF INF INF INF INF INF INF ts=1771424194.790443 msg=GOMEMLIMIT is updated package=github.com/KimMachineGun/automemlimit/memlimit GOMEMLIMIT=7609260441 INF INF INF INF INF INF INF INF ts=1771424194.790443 INF INF INF INF INF INF INF INF ts=1771424194.790443 msg=GOMEMLIMIT is updated INF INF INF INF INF INF INF INF ts=1771424194.790443 INF INF INF INF INF INF INF INF ts=1771424194.790443 msg=GOMEMLIMIT is updated package=github.com/KimMachineGun/automemlimit/memlimit INF INF INF INF INF INF INF INF ts=1771424194.790443 INF INF INF INF INF INF INF INF ts=1771424194.790443 msg=GOMEMLIMIT is updated INF INF INF INF INF INF INF INF ts=1771424194.790443 INF INF INF INF INF INF INF INF ts=1771424194.790443 msg=GOMEMLIMIT is updated package=github.com/KimMachineGun/automemlimit/memlimit GOMEMLIMIT=7609260441 previous=9223372036854776000
INF INF INF INF INF INF INF INF ts=1771424194.7916586 INF INF INF INF INF INF INF INF ts=1771424194.7916586 msg=using config from file INF INF INF INF INF INF INF INF ts=1771424194.7916586 INF INF INF INF INF INF INF INF ts=1771424194.7916586 msg=using config from file file=/tmp/Caddyfile
INF INF INF INF INF INF INF INF ts=1771424194.7943504 INF INF INF INF INF INF INF INF ts=1771424194.7943504 msg=adapted config to JSON INF INF INF INF INF INF INF INF ts=1771424194.7943504 INF INF INF INF INF INF INF INF ts=1771424194.7943504 msg=adapted config to JSON adapter=caddyfile
INF INF INF INF INF INF INF INF ts=1771424194.807683 INF INF INF INF INF INF INF INF ts=1771424194.807683 msg=serving initial configuration

Configuration

Nextcloud

The output of occ config:list system or similar is best, but, if not possible, the contents of your config.php file from /path/to/nextcloud is fine (make sure to remove any identifiable information!):

*No changes was done manually on the config.php.

<?php
$CONFIG = array (
  'one-click-instance' => true,
  'one-click-instance.user-limit' => 100,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'check_data_directory_permissions' => false,
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => 'nextcloud-aio-redis',
    'password' => '<hidden>',
    'port' => 6379,
  ),
  'overwritehost' => '<my-custom-domain>',
  'overwriteprotocol' => 'https',
  'passwordsalt' => '<hidden>',
  'secret' => '<hidden>',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => '<my-custom-domain>',
  ),
  'datadirectory' => '/mnt/ncdata',
  'dbtype' => 'pgsql',
  'version' => '32.0.4.1',
  'overwrite.cli.url' => '<hidden>',
  'dbname' => 'nextcloud_database',
  'dbhost' => 'nextcloud-aio-database:5432',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'oc_nextcloud',
  'dbpassword' => '<hidden>',
  'installed' => true,
  'instanceid' => 'ocidm99ao9ld',
  'maintenance' => false,
  'loglevel' => 3,
  'log_type' => 'file',
  'logfile' => '/var/www/html/data/nextcloud.log',
  'log_rotate_size' => 10485760,
  'log.condition' =>
  array (
    'apps' =>
    array (
      0 => 'admin_audit',
    ),
  ),
  'preview_max_x' => 2048,
  'preview_max_y' => 2048,
  'jpeg_quality' => 60,
  'enabledPreviewProviders' =>
  array (
    1 => 'OC\\Preview\\Image',
    2 => 'OC\\Preview\\MarkDown',
    3 => 'OC\\Preview\\MP3',
    4 => 'OC\\Preview\\TXT',
    5 => 'OC\\Preview\\OpenDocument',
    6 => 'OC\\Preview\\Movie',
    7 => 'OC\\Preview\\Krita',
    0 => 'OC\\Preview\\Imaginary',
    23 => 'OC\\Preview\\ImaginaryPDF',
  ),
  'enable_previews' => true,
  'upgrade.disable-web' => true,
  'mail_smtpmode' => 'smtp',
  'trashbin_retention_obligation' => 'auto, 30',
  'versions_retention_obligation' => 'auto, 30',
  'activity_expire_days' => 30,
  'simpleSignUpLink.shown' => false,
  'share_folder' => '/Shared',
  'one-click-instance.link' => 'https://nextcloud.com/all-in-one/',
  'upgrade.cli-upgrade-link' => 'https://github.com/nextcloud/all-in-one/discussions/2726',
  'updatedirectory' => '/nc-updater',
  'maintenance_window_start' => 100,
  'allow_local_remote_servers' => true,
  'davstorage.request_timeout' => 7200,
  'documentation_url.server_logs' => 'https://github.com/nextcloud/all-in-one/discussions/5425',
  'htaccess.RewriteBase' => '/',
  'dbpersistent' => false,
  'auth.bruteforce.protection.enabled' => true,
  'ratelimit.protection.enabled' => true,
  'files_external_allow_create_new_local' => false,
  'trusted_proxies' =>
  array (
    0 => '127.0.0.1',
    1 => '::1',
    10 => '172.19.0.0/16',
  ),
  'preview_imaginary_url' => 'http://nextcloud-aio-imaginary:9000',
  'preview_imaginary_key' => '<hidden>',
  'data-fingerprint' => '<hidden>',
  'skeletondirectory' => '',
  'memories.db.triggers.fcu' => true,
  'memories.exiftool' => '/var/www/html/custom_apps/memories/bin-ext/exiftool-aarch64-musl',
  'memories.vod.path' => '/var/www/html/custom_apps/memories/bin-ext/go-vod-aarch64',
  'memories.vod.ffmpeg' => '/usr/bin/ffmpeg',
  'memories.vod.ffprobe' => '/usr/bin/ffprobe',
  'updatechecker' => false,
  'files.chunked_upload.max_size' => 103809024,
  'files.chunked_upload.max_parallel_count' => 1,
);

Apps

The output of occ app:list (if possible).

Tips for increasing the likelihood of a response

  • Use the preformatted text formatting option in the editor for all log entries and configuration output.
  • If screenshots are useful, feel free to include them.
    • If possible, also include key error output in text form so it can be searched for.
  • Try to edit log output only minimally (if at all) so that it can be ran through analyzers / formatters by those trying to help you.