Installing Nextcloud Files High Performance Backend (Notify Push) – Works with Cloudflare Proxy

As we can see with the latest update of Nextcloud, that is Nextcloud 21, there is a new addition which dubbed to improve the server significantly as much as ten times the previous version, well… as per their marketing(?) report. I mean, look at this graph, it sure must be something:

Huge improvement on database load from Nextcloud 20 to Nextcloud 21

The reported result is surely interesting, it is especially true for large instance with tens to hundreds of users… or even tousands, dare I say? I never heard Nextcloud instance with that much users, although it’s practically possible since Nextcloud can be optimised for high availability setup (HA).

How Significant?

Back to our use case though, the “regular self-hosting kind of guys and gals”, this addition might not introduce much noticeable performance gain if your Nextcloud has only one or few users, as stated in their blog post. It is still a good improvement though, Notify Push will reduce the time your server takes to find local file changes, making the sync time faster.

First, you no longer have to wait! Currently, the client checks every 30 seconds to see if there have been changes on the server. With the open connection, the server notifies the client of changes and it can begin downloading new files right away.

Server administrators will also be delighted. One check every 30 seconds equates to 2880 times per day. We reduced this number by 90%, only checking in once per five minutes.

That is convincing enough for me. I have personally set up Notify Push for my own Nextcloud instance and I can say that my desktop sync client is much quicker to respond file changes, the upload time is not so different however.

So without further ado, let’s try installing this Notify Push service. I will tell you first, this is not for Nextcloud installed in Docker, although the concept is more or less the same. I use baremetal server running webserver, php, and database… basically your typical LAMP setup.

Setup

First of all, I would assume that you already have:

  • Nextcloud version 21 instance up and running, if you haven’t, upgrade your Nextcloud to version 21.
  • Enabled memory caching using Redis. If you haven’t, you should… since this is the requirement. You can find the guide in their official documentation here.

With all requirement satisfied, we can proceed to install Notify Push.

Install the App from Nextcloud Appstore

Install Notify Client app from your Nextcloud web appstore. Click your profile and click Apps. Search for ”Client Push”, install it.

I already have it installed.

It’s kinda weird that the app is named notify_push when you invoke it using occ (you’ll know latter) but they call it Client Push in the appstore. But it doesn’t matter really… just my two cent.

Alright, now we need to access our server, in this case I have SSH access to my machine so I’ll use that.

$ ssh USERNAME@HOST

Once we are in, we need to configure SystemD service for Notify Push. It can be done automatically by using ”occ notify_push:setup” but we want to learn here, right?

Configure SystemD Service for Notify Push

You can use whatever text editor you prefer, I will use Nano because I love being mocked by Vim users 😛

$ nano /etc/systemd/system/notify_push.service

Add these to the file, Notify Push will setup itself using your Nextcloud config.php file, although you can also set the parameters manually, we will use config.php file here.

[Unit]
Description = Push daemon for Nextcloud clients
[Service]
Environment = PORT=7867 # Change if you already have something running on this port
Environment = NEXTCLOUD_URL=https://YOURNEXTCLOUDADDRESS.TLD
ExecStart = /var/www/nextcloud/apps/notify_push/bin/x86_64/notify_push /var/www/nextcloud/config/config.php
User=www-data
Restart = always
[Install]
WantedBy = multi-user.target

We’re done here, save it by ”ctrl+x” and press ”y”

Now we need to enable the service. Reload the daemon first then enable it:

$ systemctl daemon-reload
$ systemctl enable notify_push.service --now

Testing the Service

Second, go to your Nextcloud directory and run notify push occ command using it’s appropriate user, in which case mine is ”www-data”.

$ cd /var/www/nextcloud
$ sudo -u www-data php7.4 occ notify_push

You will see that it throws an error like so:

It’s alright, this command needs an argument, let’s try ”self-test”.

$ sudo -u www-data php7.4 occ notify_push:self-test
This is fine, it means that we need to configure reverse proxy for it.

Enabling Reverse Proxy

For Apache

Now we want to enabel reverse proxy for notify push, I use Apache2 so here’s how it’s done. First of all we need to enable some apache2 modules

$ a2enmod proxy proxy_http proxy_wstunnel
$ systemctl restart apache2

Then open your Nextcloud virtualhost file and add the following lines.

$ nano /etc/apache2/sites-available/nextclloud-le-ssl.conf

Add these lines and then save it:

    # Nextcloud Notify Push service, add these below line which says "</Directory>". It could be elsewere, just personal preference.   
    ProxyPass /push/ws ws://localhost:7867/ws
    ProxyPass /push/ http://localhost:7867/
    ProxyPassReverse /push/ http://localhost:7867/

We need to reload Apache:

$ systemctl reload apache2.service

For Nginx

If you are using Nginx, use this instead. Add the following location block to the existing server block of the nextcloud server.

location /push/ {
    proxy_pass http://127.0.0.1:7867/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Now reload Nginx:

$ sudo nginx -s reload

Setup Notify Push

Now go to your Nextcloud root directory and run the setup command

$ cd /var/www/nextcloud
$ sudo -u www-data php7.4 occ notify_push:setup https://YOUR.NEXTCLOUD-DOMAIN.TLD/push

You will get results like this:

Press ENTER
Then you will get this, it means that your setup is successful!

We Are Finished

You can check it by using occ:notify_push:self-test in your Nextcloud root directory:

$ sudo -u www-data php7.4 occ notify_push:self-test
All is up and well.

That’s all, your Notify Push service is installed, enjoy the improved performance.

For Cloudflare Users

But, how about Cloudflare users? With Cloudflare enabled, you will probably get an error like so:

Error due to Cloudflare proxy not being defined in your Nextcloud trusted proxies.

We can fix this by adding Cloudflare IPs to your trusted proxy in config.php. The IPs are listed here: https://www.cloudflare.com/ips/

Cloudflare IPs page

Those are the definitive source of Cloudlfare’s proxy IP addresses. When there are new updates, those list will be updated too so keep an eye on that.

We will add those IPs to our config.php:

$ nano /var/www/nextcloud/config/config.php

Add the list of IPs after these lines:

Add Cloudflare IPs there, I just made that list number 3 to 14
Edit them so it looks like the following^

I already have 2 proxies hence Cloudflare IPs are listed from number 3 below. You can copy the list below and adapt it to your config.php

Please note however that Cloudflare IPs may change, thus you need to check it here: https://www.cloudflare.com/ips/ to make sure that your list is updated.

'trusted_proxies' => array ( 
    0 => '127.0.0.1', 
    1 => 'YOUR IP', 
    2 => 'YOUR OTHER IP, IF ANY', 
    3 => '173.245.48.0/20', 
    4 => '103.21.244.0/22', 
    5 => '103.22.200.0/22', 
    6 => '103.31.4.0/22', 
    7 => '141.101.64.0/18', 
    8 => '108.162.192.0/18', 
    9 => '190.93.240.0/20', 
    10 => '188.114.96.0/20', 
    11 => '197.234.240.0/22', 
    12 => '198.41.128.0/17', 
    13 => '162.158.0.0/15', 
    14 => '104.16.0.0/12', 
    15 => '172.64.0.0/13', 
    16 => '131.0.72.0/22', 
),

Save the config.php file, and we are done. We can see that Notify Push can recognise Cloudflare IP as a proper proxy now.

$ sudo -u www-data php7.4 occ notify_push:self-test
Success!

And that’s all, we are done!!! 😀

Posts created 3

Leave a Reply

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
%d bloggers like this: