Setting Up NextCloud on Synology NAS with SSL Certificate

NextCloud is one of the best open-source cloud storage solutions, offering performance comparable to commercial alternatives. With Synology’s Docker package, installing NextCloud is a breeze. However, the default NextCloud image in Synology’s registry can be difficult to download. In this tutorial, we’ll use the linuxserver/nextcloud image, which has a minor caveat: it enables HTTPS encryption by default, requiring a domain certificate to function.

Step 1: Obtaining an SSL Certificate

To obtain an SSL certificate, we’ll use the FreeSSL.cn website. Follow the website’s guidelines to download the KeyManager software, verify your domain, and apply for a certificate. Export the certificate in Nginx format.

In the Synology Control Panel, navigate to Security > Certificate, and select Add > Import Certificate. Import the .csr and .key files generated in the previous step. This will successfully add the SSL certificate.

Note: This step may require a public IP address. If you don’t have a public IP address, you may need to use alternative methods, such as port forwarding.

Step 2: Configuring and Running NextCloud in Docker

Double-click the linuxserver/nextcloud image in Docker to create a container. In the container configuration, set up port mapping and storage settings.

Map the container’s ports 443 and 80 to ports 2443 and 2080, respectively. Create two directories on your Synology NAS to persist data: /docker/nextcloud/data and /docker/nextcloud/config. Map these directories to the container’s /data and /config directories, respectively.

Additionally, create a file containing a random string for encryption and map it to the container’s /run/secrets/mysecretpassword file. After completing these settings, the container should start normally.

Step 3: Configuring the Database

During the first login to NextCloud, you’ll need to configure the administrator account, password, and database. The default SQLite3 database is only suitable for testing purposes; in practice, you should use a standard database like MySQL.

In this example, we’ve already installed MariaDB (a MySQL-compatible database) on the Synology NAS using the built-in package. Fill in the database username, password, and other information to connect to the database.

Note: If you’re using an external domain name and port to access the database, the connection speed may be slow. To improve the connection speed, use the docker inspect <container_id> command to query the Docker container information, and find the host machine’s IP address in the Docker network (default is 172.17.0.1). Use this IP address in the database IP address field.

By following these steps, you’ll have a secure NextCloud installation on your Synology NAS with an SSL certificate. Enjoy your private cloud storage solution!