Nextcloud: Difference between revisions

imported>Onny
Add objectstore example
imported>Pschwede
Tips and tricks: How to run nextcloud in a sub-directory
Line 330: Line 330:
};
};
</nowiki>}}
</nowiki>}}
=== Run nextcloud in a sub-directory ===
Say, you don't want to run nextcloud at <code>your.site/</code> but in a sub-directory <code>your.site/nextcloud/</code>. To do so, use port-forwarding and a few rewrite-rules.
First, define some overwritings. Nextcloud uses them to write URLs in its links as if it was running in a sub-directory (which it is not.)
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
services.nextcloud = {
  settings = let
    prot = "http"; # or https
    host = "127.0.0.1";
    dir = "/nextcloud";
  in {
    overwriteprotocol = prot;
    overwritehost = host;
    overwritewebroot = dir;
    overwrite.cli.url = "${prot}://${host}${dir}/";
    htaccess.RewriteBase = dir;
  };
};
</nowiki>}}
Make sure your nginx doesn't host nextcloud on your exposed port:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
services.nginx.virtualHosts."${config.services.nextcloud.hostName}".listen = [ {
  addr = "127.0.0.1";
  port = 8080; # NOT an exposed port
} ];
</nowiki>}}
Redirect some well-known URLs which have to be found at your.site/.well-known towards your new nextcloud URL:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
services.nginx.virtualHosts."localhost" = {
  "^~ /.well-known" = {
            priority = 9000;
            extraConfig = ''
              absolute_redirect off;
              location ~ ^/\\.well-known/(?:carddav|caldav)$ {
                return 301 /nextcloud/remote.php/dav;
              }
              location ~ ^/\\.well-known/host-meta(?:\\.json)?$ {
                return 301 /nextcloud/public.php?service=host-meta-json;
              }
              location ~ ^/\\.well-known/(?!acme-challenge|pki-validation) {
                return 301 /nextcloud/index.php$request_uri;
              }
              try_files $uri $uri/ =404;
            '';
          };
};
</nowiki>}}
Finally, forward <code>your.site/nextcloud/</code> (exposed port 80 or 443) to your unexposed nextcloud port 8080 (defined earlier):
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
services.nginx.virtualHosts."localhost" = {
  "/nextcloud/" = {
        priority = 9999;
        extraConfig = ''
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-NginX-Proxy true;
          proxy_set_header X-Forwarded-Proto http;
          proxy_pass http://127.0.0.1:8080/; # tailing / is important!
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
          proxy_redirect off;
        '';
      };
}
</nowiki>}}
Note: If you have SSL (https) enabled, make sure nginx forwards to the correct port and nextcloud overwrites for the correct protocol.


== Troubleshooting ==
== Troubleshooting ==