Use nextcloud on local and publish to internet

Tram Ho

The goal of this article is to use Nextcloud as a local data storage system and publish that system to the internet via VPS so that Nextcloud can be accessed locally from anywhere.

Prepare

I assume you already have 1 VPS working and have 1 domain drive.example.com pointed to VPS I use cloudflare’s service to manage domains, as well as to be able to use https for my domain You Need an old laptop to run Nextcloud on docker

You need to know the basics of docker to be able to continue this article

Step 1: Install Nextcloud on your Laptop

Install Nextcloud on your laptop using docker and docker-compose, this is a basic file to run Nextcloud on docker, note that you should change the password for MYSQL_ROOT_PASSWORD and MYSQL_PASSWORD when using on production environment

docker-compose.yml

When the initialization is complete, you can access Nextcloud with the address http://localhost:8080 and log in with the admin account and password that you created when installing Nextcloud

Once this step is done, you can use Nextcloud to store your data on your laptop, but you can only access Nextcloud locally, if you want to access Nextcloud locally from anywhere then you need to publish Nextcloud locally to the internet we will do in the next step

Step 2: Link Local Nextcloud with VPS using P2P network

I use Zerotier to create a P2P network between my laptop and VPS, then you can access Nextcloud at VPS using http://<IP of LAPTOP>:8080

You go to https://my.zerotier.com to create an account and create a network, assuming your network ID is 1234567890abcdef

On VPS, you need to install Zerotier and join network 1234567890abcdef , similarly on laptop, you need to install Zerotier and join network 1234567890abcdef

After joining, you can access Nextcloud on VPS with http://<IP of LAPTOP>:8080

IP of LAPTOP can be viewed at https://my.zerotier.com or you can use Zerotier One to view IP of regular LAPTOP, to avoid IP conflict, you should avoid using IP range 192.168.xx(LOCAL ) and 10.xxx (VPS) you can use IP range 172.16.xx

When your VPS and laptop are online, zerotier will automatically create a P2P network between these two devices, and give each node 1 IP in the range 172.16.xx

Assuming the laptop’s IP is 172.16.0.123, when you access http://172.16.0.123:8080 , you will access Nextcloud on the laptop

I choose Zerotier to create a P2P network between a laptop and a VPS because it’s easy and free, in addition, it supports many different operating systems and can be used on many different devices up to 25 devices (free version). )

Step 3: Publish Nextcloud locally to the internet

After step 2 you can access nextcloud on VPS with the address http://172.16.0.123:8080 , but if you want to access nextcloud by domain, you must use a reverse proxy to point the domain to Nextcloud http address ://172.16.0.123:8080 and configure SSL for the domain

You can use nginx-proxy-manager to do reverse proxy and configure SSL for domain, below is sample file to configure nginx-proxy-manager using docker

docker-compose.yml

After the configuration is complete, you can access nginx-proxy-manager at http://<IP of VPS>:81 to configure the proxy to point the domain to your Nextcloud

Complete System Flow

image.png

The subsection you can refer to

Configure SSL for the domain

I use cloudflare to manage domains and configure SSL for domains, you can use cloudflare or another service to manage domains and configure SSL for domains

You can configure SSL for the domain using cloudflare proxy, note that it is recommended to use full SSL mode (you generate SSL certificate in cloudflare and download and install it on VPS)

Things to do when publishing Nextcloud locally to the internet

  1. add Trusted Domains to your Nextcloud
  2. config force https in your Nextcloud in the file config.php key overprotocol => ‘https’, you can read more here https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/reverse_proxy_configuration.html
  3. Some apps you need to install to make your Nextcloud work better such as: TOTP (2-factor authentication), pdf viewer, raw preview…
  4. cron.php may not run if you don’t configure cronjob for your Nextcloud, you can read more here https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/background_jobs_configuration.html
Share the news now

Source : Viblo