The recommended way to run a self hosted NextCloud instance is using the All in One Docker image officially provided by Nextcloud GmbH (see https://hub.docker.com/r/nextcloud/all-in-one/) as described on their website ( see https://nextcloud.com/install/#instructions-server).
If you have a server running Plesk and want to use the official aio docker image as described above there are a few pitfalls, but basically everything should run smoothly if you follow my instructions below.
I assume you already have a docker deamon up and running and created a domain / subdomain through plesk that is fitted with a ssl certificate. As plesk is running and there is (to my knowledge) no way to completely overwrite settings in a way to directly expose the NextCloud AIO docker container to the public, we’ll need to find a way to proxy the requests through nginx. As plesk is defaultly running in a mode where it proxies requests through nginx to apache, this is not going to be a problem.
There is a special documentation about running NextCloud behind a proxy, as this is not considered the default mode of the NextCloud AIO docker image. You can find the complete guide at https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md with a pre configured compose file at https://github.com/nextcloud/all-in-one/blob/main/compose.yaml that can be adjusted to your needs. Basically my compose file looks like this:
Basic compose.yml file for NextCloud AIO docker image behind an nginx reverse proxy
services:
nextcloud-aio-mastercontainer:
image: nextcloud/all-in-one:latest
init: true
restart: always
container_name: nextcloud-aio-mastercontainer # This line is not allowed to be changed as otherwise AIO will not work correctly
volumes:
- nextcloud_aio_mastercontainer:/mnt/docker-aio-config # This line is not allowed to be changed as otherwise the built-in backup solution will not work
- /var/run/docker.sock:/var/run/docker.sock:ro # May be changed on macOS, Windows or docker rootless. See the applicable documentation. If adjusting, don't forget to also set 'WATCHTOWER_DOCKER_SOCKET_PATH'!
ports:
- 8080:8080
environment: # Is needed when using any of the options below
# - AIO_DISABLE_BACKUP_SECTION=false # Setting this to true allows to hide the backup section in the AIO interface. See https://github.com/nextcloud/all-in-one#how-to-disable-the-backup-section
- APACHE_PORT=11000
- APACHE_IP_BINDING=0.0.0.0
volumes: # If you want to store the data on a different drive, see https://github.com/nextcloud/all-in-one#how-to-store-the-filesinstallation-on-a-separate-drive
nextcloud_aio_mastercontainer:
name: nextcloud_aio_mastercontainer # This line is not allowed to be changed as otherwise the built-in backup solution will not work
Please refer to the example compose file in the link above to further adjust this to your settings, as this is only the basic configuration you’ll need to make nextcloud run behind a reverse proxy. This will make nextclouds’ apache container serve on port 11000, hence this is where we’ll proxy our requests to.
Configuring plesk to only run nginx as a proxy for the NextCloud AIO docker image
In plesk, go to the domain you wan’t to server NextCloud under. It is not possible to run NextCloud in subdirectory, as the authors of NextCloud did not intent for it to do so, so you’ll definitley need a domain with a valid ssl certificate which you can acquire through plesk via Let’s Encrypt (https://letsencrypt.org/). Now go to your domain in Plesk and under “Hosting & DNS” choose “Apache & nginx”.
The first thing you’ll want to do is to uncheck the proxy mode, which will turn off Apache for this domain overall. We only need nginx to proxy our requests to the NextCloud AIO docker container. Next we’ll want to add additional nginx directives to tell nginx to actually proxy our requests:
location ~ ^/.* {
proxy_pass http://127.0.0.1:11000$request_uri;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Accept-Encoding "";
proxy_set_header Host $host;
client_body_buffer_size 512k;
proxy_read_timeout 86400s;
client_max_body_size 0;
# Websocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
Disabling php is important for NextCloud to run in docker under Plesk
In Plesk go to the Dashboard under your domain and under “Dev Tools” choose “PHP”. There you’ll need to uncheck PHP support. Otherwise NextCloud will not work properly as Plesk automatically generates directives in the nginx configuration which will interfere with NextCloud. If you’re NextCloud is working in general but producing various 404 errors whilst working with it, there is probably still some problem with nginx directives coming directly from Plesk. I discovered it when the NextCloud Frontend tried to send xhr requests to the URI ocs/v2.php which resulted in a Not Found error.
Adding required nginx variables to the server config
As we’ll need to tell nginx about the variables we used in the additional directives and we cannot do it there (we’ll be in a section where this is not allowed), we’ll need to add this mapping manually. This requires root access to your servers config files. In my knowledge there is no way to do this directly via Plesk, which is why I added the configuation manually. To not interfere with Plesk (which is regularly recreating configuration files), I added a new file called map.conf to nginxs’ conf.d directory.
# this file is /etc/nginx/conf.d/map.conf
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
Now all you need to do is to tell nginx to reload it’s config by executing the following command:
nginx -s reload
That’s it! You can now fire up NextCloud AIO Docker Image and follow the instructions from the manual, it is pretty straight forward from here on.
Leave a Reply