NextCloud Service¶
NextCloud is a program that can give you multiple services using extension mechanism: * Shared files across multiple computers and web (like Google Drive or Microsoft One-Drive) * shared calendar/contacts * Skype like service * collaborative document edition * etc
See NextCloud home page for more details.
Suppose that you want to serve Nextcloud on the following address: https://drive.mydomain.com
Note
Big thank you to Benjamin and Laury that gave me their docker-compose file that was used as a base for this tutorial.
configure your node to support docker-compose¶
You need to install and configure docker and docker-compose on you node see the docker and docker-compose pages.
docker-compose file¶
Create a directory where to put all your docker-compose stuff.
For instance: /usr/local/services/NextCloud/
Create a 'docker-compose.yml' file with this content:
---
version: "3"
services:
nextcloud:
container_name: nextcloud
labels:
mydomain.service: nextcloud
logging:
driver: json-file
depends_on:
- nextcloud_db
- nextcloud_redis
image: nextcloud:${NEXTCLOUD_VERSION}
networks:
- nextcloud
environment:
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=${NEXTCLOUD_DB_PASSWORD}
- MYSQL_HOST=nextcloud_db
- NEXTCLOUD_TRUSTED_DOMAINS=drive.mydomain.com
- REDIS_HOST=nextcloud_redis
- REDIS_HOST_PASSWORD=${NEXTCLOUD_REDIS_PASSWORD}
ports:
- 8000:80
volumes:
- ${VOLUME_BASE_ROOT}/nextcloud/nextcloud:/var/www/html
- ${VOLUME_BASE_ROOT}/nextcloud/data:/var/www/html/data
- ${VOLUME_BASE_ROOT}/nextcloud/config:/var/www/html/config
restart: unless-stopped
nextcloud_db:
container_name: nextcloud_db
labels:
mydomain.service: nextcloud
logging:
driver: json-file
image: mariadb
networks:
- nextcloud
environment:
- MYSQL_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD}
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=${NEXTCLOUD_DB_PASSWORD}
- MYSQL_DATABASE=nextcloud
volumes:
- ${VOLUME_BASE_ROOT}/nextcloud/db:/var/lib/mysql
- ${VOLUME_BASE_ROOT}/nextcloud/db_backup:/var/lib/backup
restart: unless-stopped
nextcloud_redis:
container_name: nextcloud_redis
labels:
mydomain.service: nextcloud
logging:
driver: json-file
image: redis
networks:
- nextcloud
environment:
- REDIS_DATABASES=1
volumes:
- ${VOLUME_BASE_ROOT}/nextcloud/redis:/var/lib/redis
command: redis-server --requirepass ${NEXTCLOUD_REDIS_PASSWORD}
restart: unless-stopped
networks:
nextcloud:
driver: bridge
Do not forget to change values with your domain.
This file is not enough to have all things working. As you can see there are some environment variables that must be passed to docker in order to have this configuration works.
Note
Service will be on port 8000 (you can change this if you need)
Note
With the restart value set to unless-stopped this service will restart right after the node reboot. Hence, you won't have to restart it by hand each time the node reboots.
To give the environment variables to docker-compose create a file .env with this content:
VOLUME_BASE_ROOT=./Volumes/
NEXTCLOUD_VERSION=20
NEXTCLOUD_DB_PASSWORD=MY_PASSWORD_FOR_THE_DB
NEXTCLOUD_REDIS_PASSWORD=MY_PASSWORD_FOR_REDIS
MARIADB_ROOT_PASSWORD=MY_PASSWORD_FOR_MARIADB
VOLUME_BASE_ROOT is the location where the volumes will be placed. With the current value, it will put all volumes to /usr/local/services/NextCloud/Volumes/xxx. This can simplify the backup process, or the cleaning if you go back uninstalling NextCloud.
NEXTCLOUD_VERSION must be set to the version you plan to use, 20 is the latest stable at the time of writing.
XXX_PASSWORD Change the password for each sub service.
configure your reverse proxy¶
In order to have things works correctly, you will have to configure all the stuff in Apache configuration file.
You can find some information about how to configure your reverse proxy here.
For instance, if your server's IP is 123.170.5.250 nd you leaved the port on 8000
(...)
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName drive.mydomain.com
ServerAlias drive.mydomain.com
(...)
ProxyPass / http://123.170.5.250:8000/
ProxyPassReverse / http://123.170.5.250:8000/
ProxyRequests Off
AllowEncodedSlashes NoDecode
(...)
</VirtualHost>
</IfModule>
Starting the service¶
To start the service you have to go in your installation directory: /usr/local/services/NextCloud/
Then, as administrator, you will have to run the following command:
docker-compose up -d
configure your server infos¶
According to NextCloud documentation, the server's URL can be wrongly detected.
This can be seen when you try to access the service on your local network: it displays the IP instead of your domain name, even when you try to connect with it. For instance, I was not able to register the desktop app to anything else than the IP on my laptop (it should be OK when working only at home, but as soon as I connect from anywhere else it won't work anymore).
To ensure the server's URL is set correctly set, you can edit the NextCloud configuration file to add hardcoded values.
Here are the line I've added to the file /usr/local/services/NextCloud/Volumes/nextcloud/config/config.php
'overwrite.cli.url' => 'drive.mydomain.com',
'overwritehost' => 'drive.mydomain.com',
'overwriteprotocol' => 'https',