Running Nextcloud13 in a subfolder with other services unaffected (nginx)?

Nextcloud version (eg, 12.0.2): 13.0.0.10 (RC1)
Operating system and version (eg, Ubuntu 17.04): Ubuntu 16.04
Apache or nginx version (eg, Apache 2.4.25): Nginx (latest in Ubuntu 16.04)
PHP version (eg, 7.1): 7.0

The issue you are facing:

Steps to replicate it:

  1. Try to install Nextcloud in a subdirectory following this tutorial: https://docs.nextcloud.com/server/12/admin_manual/installation/nginx.html#nextcloud-in-a-subdir-of-nginx
  2. Also have other services running in the root directory and other parallel sub directories
  3. Notice that loading of .js .css images and various other files fail in the other services due to Nginx rewrite rules

The output of your Nextcloud log in Admin > Logging:

Error	index	Exception: The requested uri(/otherservice/static/jquery.js) cannot be processed by the script '/cloud/index.php')

Lots of those errors. And Nextcloud asks the user to log in again if you open the other services.

I assume this is related to these rewrite rules that don’t descriminate with subfolder the files are in:

location ~ \.(?:css|js|woff|svg|gif)$ {
            try_files $uri /nextcloud/index.php$uri$is_args$args;
            add_header Cache-Control "public, max-age=15778463";
            access_log off;
        }

and

location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
            try_files $uri /nextcloud/index.php$uri$is_args$args;
            # Optional: Don't log access to other assets
            access_log off;
        }

Anyone got a hint how that can’t be made to work? I am relatively new to nginx and php, so please give sufficient detail. I already tried googling quite a bit, but I can’t seem to figure it out. In Apache there are .htaccess files to solve such issue I guess.

Another unrelated thing: If I don’t remove this part

location ~ ^/nextcloud/(?:updater|ocs-provider)(?:$|/) {
            try_files $uri/ =404;
            index index.php;
        }

My new Nextcloud doesn’t seem to save any settings or give notifications etc. Very strange…

I am running nextcloud in a subdir along with other services without any problems. The locations you mentioned are nested under the location ^~ /nextcloud which means that only requests starting with /nextcloud are matching those locations.

There seems to be something wrong with your configuration. Could you post your nginx configuration?

Edit: there is a good read about nginx location block selection algorithms at digitalocean which helped me a lot: https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms

1 Like

Thanks… on closer inspection it seems like I missed the nesting of the first /nextcloud location block. A bit confusing that there are two.