1

I use a Ngnix reverse proxy to keep several docker services behind HTTPS and in the same DNS.

Basically I want to access to Nextcloud with: https://server.<my-dns>.fr/cloud/
I have access to the initialisation page but all dependencies don't load (css, js, images ...) because the base URL seems incorrect.

For example my browser try to load https://server.<my-dns>.fr/core/js/dist/main.js while the correct one is https://server.<my-dns>.fr/cloud/core/js/dist/main.js

My others services work as expected but not this one.

nginx.conf

events { }

http {
  proxy_cache_path /tmp/cache keys_zone=one:10m;

  # HTTP
  server {
    listen 80;
    server_name server.<my-dns>.fr;

    # For SSL cretificate validation
    location /.well-known/acme-challenge/ {
      root /var/www/certbot;
    }

    # Redirect everything to https
    location / {
      return 301 https://$host$request_uri;
    }
  }

  # HTTPS
  server {
    listen 443 ssl;
    server_name server.<my-dns>.fr;

    # HTTPS configuration
    ssl_certificate /etc/letsencrypt/live/server.<my-dns>.fr/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/server.<my-dns>.fr/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    # Auth configuration
    auth_basic "Registry realm";
    auth_basic_user_file /etc/nginx/conf.d/nginx.htpasswd;

    location /glance/ {
      proxy_pass http://localhost:61208/;
      rewrite ^/glance(.*)$ $1 break;
    }

    # Other services ...

    location /cloud/ {
      auth_basic off;
      proxy_pass http://localhost:8181/;
      rewrite ^/cloud(.*)$ $1 break;
    }
  }
}

docker-compose.yml

version: '3'

services:
  nextcloud_db:
    image: mariadb
    container_name: nextcloud_db
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: unless-stopped
    volumes:
      - ./data/db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=*****
      - MYSQL_PASSWORD=*****
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    image: nextcloud
    ports:
      - 8181:80
    links:
      - nextcloud_db
    volumes:
      - ./data/nextcloud:/var/www/html
    restart: unless-stopped
    depends_on:
      - nextcloud_db

I understand that Nginx don't rewrite the dependencies URLs but how to solve this?
I tried to change the Nextcloud base url settings but without success. I also tried this Nextcloud in a subdir of nginx guide but I don't really understand it.

Opsse
  • 131
  • 1
  • 6

2 Answers2

2

Try this:

location /cloud/ {
  auth_basic off;
  proxy_pass http://localhost:8181/;
  rewrite ^/cloud(.*)$ $1 break;
  sub_filter "/core/" "/cloud/core/";
  sub_filter_once off;
}


This replaces all /core/ to /cloud/core/ in the response of the proxy pass.

ngx_http_sub_module

This may fix your problem but I would recommend changing the base url on nextcloud, see here: https://help.nextcloud.com/t/change-url-nextcloud/52415

Shahriar Shojib
  • 322
  • 1
  • 2
  • 11
1

With the help of Shahriar Shojib answer I solved it this way:

docker-compose.yml

...
location /cloud/ {
  auth_basic off;
  proxy_pass http://localhost:8181/cloud/;
  rewrite ^/cloud(.*)$ $1 break;
}

Nextcloud config.php

...
'overwritehost' => 'server.<my-dns>.fr',
'overwritewebroot' => '/cloud'

See the Nextcloud documentation.

Opsse
  • 131
  • 1
  • 6