Nextcloud loses port in web links

Hello everybody! I need your help,please! I am almost exhausted trying to get rid of the problem described below. Google couldn’t help me((

I am running NC+MariaDB+Nginx in docker contatiners and everything works fine if I use HTTP.
However, I need to move on HTTPS. And it almost works as well. Except of one small but critical thing - port number is lost in web links. I am not sure for 100% who is guilty, ngingx or nextcloud, but I suspect nextcloud.

In a nushell - when I type

https://localhost:51623

it shows me login screen and when I enter my credentials and press enter, the link changes to just

https://localhost/index.php/apps/dashboard/

port is missing. Okay, I add port number manually in a browser and it works again when I click on some links inside NC, BUT except of link with logo of NC. When I click on it - port disappears again. It makes impossible to login from outside, for example, as all the answers fly back without port number.

My docker-compose:


  1 version: '1'
  2
  3 services:
  4   reverse_proxy:
  5     image: nginx:latest
  6     restart: always
  7     ports:
  8       - "51623:443"
  9     container_name: nginx-reverse
 10     depends_on:
 11       - database
 12       - nextcloud
 13     volumes:
 14       - /home/observer/BKP/nextcloud/nginx:/etc/nginx/conf.d
 15     networks:
 16       - nextcloud-net                                                                                                                                                                                                                    
 17
 18   database:
 19    image: mariadb
 20    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --skip-innodb-read-only-compressed
 21    restart: always
 22    volumes:
 23      -  /home/observer/BKP/nextcloud/mariadb:/var/lib/mysql
 24    container_name: mariadb-docker
 25    environment:
 26      - MYSQL_ROOT_PASSWORD=ABC123
 27      - MYSQL_PASSWORD=DEF456
 28      - MYSQL_DATABASE=nextcloud
 29      - MYSQL_USER=nextcloud
 30    networks:
 31    - nextcloud-net
 32
 33   nextcloud:
 34     image: nextcloud
 35     restart: always
 36     container_name: nextcloud-docker
 37     volumes:
 38       - /home/observer/BKP/nextcloud/apps:/var/www/html/apps
 39       - /home/observer/BKP/nextcloud/config:/var/www/html/config
 40       - /home/observer/BKP/nextcloud/data:/var/www/html/data
 41     networks:
 42      - nextcloud-net
 43
 44 networks:
 45   nextcloud-net:

default.conf on NGINX is :

server {
                listen       443 ssl http2;
                server_name cloud.example.com;

                ssl_certificate /etc/nginx/conf.d/nginx-selfsigned.crt;
                ssl_certificate_key /etc/nginx/conf.d/nginx-selfsigned.key;

                location / {
                                #       root /var/www/localhost/htdocs;
                                proxy_pass          http://nextcloud-docker/;
                                proxy_set_header    Host $host;
                                proxy_set_header    X-Real-IP $remote_addr;
                                proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
                                proxy_set_header    X-Forwarded-Proto $scheme;
                                add_header                      Front-End-Https on;
                                proxy_redirect          default;
                }


}

and config.php is:

<?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,
    ),
  ),
  'instanceid' => 'occpfusc1bg7',
  'passwordsalt' => '8UbBfHEu/UIepRLq+XT9ooa2MMLfIs',
  'secret' => 'i6iXTsI8hC1zH2H8aoA8DnvGwPZwZCSl+akntkE/ZagJ5IHg',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => '192.168.0.111',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '25.0.3.2',
  'overwriteprotocol' => 'https',
  'overwrite.cli.url' => '',
  'dbname' => 'nextcloud',
  'dbhost' => 'mariadb-docker',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'DEF456',
  'installed' => true,
);

Does anybody have an idea why it happens?

I send you back rays of luck and happiness.
Thank you in advance.

You probably need to set the overwritehost parameter in Nextcloud. It doesn’t know that the port number is changed.

https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/reverse_proxy_configuration.html#overwrite-parameters

Probably yes. But do you know what to specify there to add only port number? Because, if I set there, for instance, “localhost:51623” and went to this machine by its LAN IP adddress (192.168.0.111),

https://192.168.0.111:51623

turns into

https://localhost:51623

Is htere a kind of mask like

*:516253

I don’t think it’s possible to supply just a port number with this setting.

The real solution would be to set up split horizon DNS and use the FQDN instead of an IP, which would not need to change based on circumstances. But I don’t know how much trouble you want to go to because it’s not a simple thing.

You shouldn’t have any need to use localhost. The real problem is going to be when you need to use a public IP.