Connection Refused when accessing through nginx reverse proxy

Nextcloud version: 16.0.3
Operating system and version: CentOS 7.7.1908 / Docker 19.03.2
Apache or nginx version: Not sure.
PHP version: 7.3.7

The issue you are facing:
Cannot access nextcloud through an nginx reverse proxy

Is this the first time you’ve seen this error? : Yes

Steps to replicate it:

I set up nextcloud on my docker host and had is accessible on the local network, but I cannot make it accessible from the web.
I have a docker container running the linuxserver/letsencrypt image with an nginx reverse proxy which has some other services accessible under their own subdomains. I made the recommended changes from their config files (below) to nextcloud’s configuration and now when I access it on the local IP address it redirects me to the domain and fails to load.

# assuming this container is called "letsencrypt", edit your nextcloud container's config
# located at /config/www/nextcloud/config/config.php and add the following lines before the ");":
'trusted_proxies' => ['letsencrypt'],
'overwrite.cli.url' => 'https://nextcloud.your-domain.com/',
'overwritehost' => 'nextcloud.your-domain.com',
'overwriteprotocol' => 'https',
#
# Also don't forget to add your domain name to the trusted domains array. It should look somewhat like this:
array (
    0 => '192.168.0.1:444', # This line may look different on your setup, don't modify it.
    1 => 'nextcloud.your-domain.com',
),

When I try to load nextcloud.mydomain.tld my browser displays an nginx 502 bad gateway error, and the nginx log reads:

2019/10/13 14:37:41 [error] 364#364: 18 connect() failed (111: Connection refused) while connecting to upstream, client: 86.6.57.214, server: nextcloud., request: “GET / HTTP/2.0”, upstream: “https://172.18.0.7:443/”, host: “nextcloud.mydomain.tld”

The output of your Nextcloud log in Admin > Logging:

Can't access

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

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  '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,
    ),
  ),
  'passwordsalt' => 'REMOVED',
  'secret' => 'REMOVED',
  'trusted_domains' =>
  array (
    0 => '192.168.0.130:8082',
    1 => 'nextcloud.mydomain.tld',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '17.0.0.9',
  'overwrite.cli.url' => 'https://nextcloud.mydomain.tld/',
  'dbname' => 'nextcloud',
  'dbhost' => 'nextclouddb:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'instanceid' => 'oc3gt3zfmmph',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'REMOVED',
  'installed' => true,
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'trusted_proxies' => ['letsencrypt'],
  'overwritehost' => 'nextcloud.mydomain.tld',
  'overwriteprotocol' => 'https',
);

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

Docker image pipes these to /dev/stdout or /dev/stderr

I fixed it.

My proxy was trying to connect to nextcloud via https. Changed this to http and it works.