Nextcloud behind Ngnix reverse proxy in a subdir url

Solution 1:

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

Solution 2:

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.