Nextcloud behind NPM and Cloudflare

Hi,
I’m trying to access NC via Cloudflare —https—> NPM —https—> Nextcloud
I alwas get the Error 502 Bad Gateway

NPM Configuration (10.0.0.15):

PHP Configuration:

<VirtualHost *:80>
    UseCanonicalName Off
    ServerAdmin webmaster@localhost
    ServerName cloud.myurl.com
    ServerAlias cloud.myurl.com

    DocumentRoot /var/www/nextcloud/
    RewriteEngine On
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    ServerAdmin webmaster@localhost
    ServerName cloud.myurl.com
    ServerAlias cloud.myurl.com
    DocumentRoot /var/www/nextcloud/

    <IfModule mod_headers.c>
        Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
    </IfModule>
</VirtualHost>

<Directory /var/www/nextcloud/>
    Options +FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

NC Configuration (10.0.0.30):

<?php
$CONFIG = array (
  'passwordsalt' => '**********',
  'secret' => '**********',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => 'cloud.myurl.com',
    2 => '10.0.0.*',
  ),
  'trusted_proxies'   =>
  array (
    0 => '10.0.0.15',
  ),
  'overwriteprotocol' => 'https',
  'overwrite.cli.url' => 'https://cloud.myurl.com',
  'forwarded_for_headers' => ['HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR'],
  'datadirectory' => '/var/www/nextcloud-data',
  'dbtype' => 'mysql',
  'version' => '25.0.7.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '**********',
  'installed' => true,
  'instanceid' => '0b27388adfefb',
  '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' => '**********',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'default_phone_region' => 'DE',
  'defaultapp' => 'files',
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'ssl',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => '**********',
  'mail_domain' => 'gmail.com',
  'mail_smtpauth' => 1,
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtphost' => 'smtp.gmail.com',
  'mail_smtpport' => '465',
  'mail_smtpname' => '**********',
  'mail_smtppassword' => '**********',
);

Anybody able to help me?
Thank you!

1 Like

Hi klothoide,

In future when you post a question please provide full information of your setup since there are multiple different options.
For example… did you deploy your nextcloud on OS (what OS? ) or docker container, what web server are you using apache or fpm etc ?

By default official nextcloud installation should communicate on port 80. That means you in your reverse proxy NPM you need to create http forewarded to nextcloud instance on port 80.
For hostname you can put your “nextcloud container” (if you use docker or internal address on which nextcloud instance is accessible if you installed it on OS.
This step is explained on multiple blogs on internet.

1 Like

Hi VirtualTchniphille,
I’m running Turnkey Linux Nextcloud right out of the box.
It’s Debian 11.