How to Install Plausible on Your Synology NAS

How to Install Plausible on Your Synology NAS

Plausible Analytics is a simple, lightweight, open source and privacy-friendly alternative to Google Analytics, similar to Umami and Matomo. It doesn’t use cookies and is fully compliant with GDPR, CCPA and PECR. The mission of Plausible is to reduce corporate surveillance by providing an alternative web analytics tool which doesn’t come from the AdTech world. In this step by step guide I will show you how to install Plausible on your Synology NAS using Docker.

Note: This guide works perfectly with the latest Plausible v1.5.1 release.

  • STEP 1

Please Support My work by Making a Donation.

  • STEP 2

Install Portainer using my step by step guide. If you already have Portainer installed on your Synology NAS, skip this STEP. Attention: Make sure you have installed the latest Portainer version.

  • STEP 3

Make sure you have a synology.me Wildcard Certificate. Follow my guide to get a Wildcard Certificate. If you already have a synology.me Wildcard certificate, skip this STEP.

  • STEP 4

Go to Control Panel / Login Portal / Advanced Tab / click Reverse Proxy. Follow the instructions in the image below.

Plausible Synology NAS Set up 1

  • STEP 5

Now click the “Create” button. Follow the instructions in the image below.

Plausible Synology NAS Set up 2

  • STEP 6

After you click the Create button, the window below will open. Follow the instructions in the image below.

On the General area, set the Reverse Proxy Name description: type in Plausible. After that, add the following instructions:

Source:
Protocol: HTTPS
Hostname: plausible.yourname.synology.me
Port: 443

Check Enable HSTS

Destination:
Protocol: HTTP
Hostname: localhost
Port: 9850

Plausible Synology NAS Set up 3

  • STEP 7

On the Reverse Proxy Rules click the Custom Header tab. Click Create and then, from the drop-down menu, click WebSocket. After you click on WebSocket, two Header Names and two Values will be automatically added. Click Save. Follow the instructions in the image below.

Synology Proxy WebSocket

  • STEP 8

Go to Control Panel / Network / Connectivity tab/ Check Enable HTTP/2 then click Apply. Follow the instructions in the image below.

Plausible Synology NAS Set up 4

  • STEP 9

Go to Control Panel / Security / Advanced tab/ Check Enable HTTP Compression then click Apply. Follow the instructions in the image below.

Plausible Synology NAS Set up 5

  • STEP 10

Go to File Station and open the docker folder. Inside the docker folder, create one new folder and name it plausible. Follow the instructions in the image below.
Note: Be careful to enter only lowercase, not uppercase letters.

Plausible Synology NAS Set up 6

  • STEP 11

Now create three new folders inside the plausible folder that you created at STEP 10 and name them data, db, logs. Follow the instructions in the image below.
Note: Be careful to enter only lowercase, not uppercase letters.

Plausible Synology NAS Set up 7

  • STEP 12

Log into Portainer using your username and password. On the left sidebar in Portainer, click on Stacks then + Add stack. Follow the instructions in the image below.

1 Synology Portainer Add Stack

  • STEP 13

In the Name field type in plausible. Follow the instructions in the image below.

Note: Copy Paste the code below in the Portainer Stacks Web editor.

version: "3.9"
services:
  db:
    image: postgres:14-alpine
    container_name: Plausible-DB
    hostname: plausible_db
    security_opt:
      - no-new-privileges:true
    volumes:
      - /volume1/docker/plausible/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=plausible_db
      - POSTGRES_PASSWORD=postgres
    restart: always

  events-db:
    image: clickhouse/clickhouse-server:22.6-alpine
    ulimits:
      nofile:
        soft: 262144
        hard: 262144
    container_name: Plausible-EVENTS-DB
    hostname: plausible_events_db
    security_opt:
      - no-new-privileges:true
    user: 1026:100
    volumes:
      - /volume1/docker/plausible/data:/var/lib/clickhouse
      - /volume1/docker/plausible/logs:/var/log/clickhouse-server
    restart: always
    
  mail:
   image: bytemark/smtp
   container_name: Plausible-SMTP
   hostname: mail
   restart: always
   #environment:
      #RELAY_HOST: smtp.gmail.com
      #RELAY_PORT: 587
      #RELAY_USERNAME: Your-own-gmail-address
      #RELAY_PASSWORD: Your-own-app-password
      
  plausible:
    image: plausible/analytics:latest
    command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin && /entrypoint.sh run"
    container_name: Plausible
    hostname: plausible
    security_opt:
      - no-new-privileges:true
    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://localhost:8000/ || exit 1
    ports:
      - 9850:8000
    environment:
      - BASE_URL=https://plausible.yourname.synology.me
      - SECRET_KEY_BASE=fE2Z9z9idAfGOHzl3fAz1x4/zneBI3oel9R38k8icc6Ttlm0ZtLp3MS5Gd6RNhPzKEFpe3DeeL6x2rMm/+WZLQ==
    restart: always
    depends_on:
      - db
      - events-db
      - mail

Note: Before you paste the code above in the Web editor area below, change the value numbers for user with your own UID and GID values. (Follow my step by step guide on how to do this.) 1026 is my personal UID value and 100 is my personal GID value. You have to type in your own values.
Note: If you want, you can also add your own SMTP email details by removing all the # in the code above. If you don’t have SMTP details, then leave the code as it is with the #. (Follow my guide on how to Activate Gmail SMTP For Docker Containers.)
Note: Before you paste the code above in the Web editor area below, change the value for BASE_URL and type in your own synology.me DDNS with https:// at the beginning that you have previously created at STEP 6.

Plausible Synology NAS Set up 8

  • STEP 14

Scroll down on the page until you see a button named Deploy the stack. Click on it. Follow the instructions in the image below. The installation process can take up to a few minutes. It will depend on your Internet speed connection.

Plausible Synology NAS Set up 9

  • STEP 15

If everything goes right, you will see the following message at the top right of your screen: “Success Stack successfully deployed“.

Plausible Synology NAS Set up 10

  • STEP 16

Go back to STEP 1 or you will deal with karma 🙂.

  • STEP 17

Now open your browser and type in your HTTPS/SSL certificate like this https://plausible.yourname.synology.me In my case it’s https://plausible.mariushosting.synology.me If everything goes right, you will see the Plausible main page. Type in your full name, your own email address and your own password. Confirm the password then click Create my account. Follow the instructions in the image below.

Plausible Synology NAS Set up 11

  • STEP 18

In the domain field type in your own domain name that you want to monitor. Select your Timezone then click Add snippet. Follow the instructions in the image below.

Plausible Synology NAS Set up 12

  • STEP 19

Copy your own JavaScript snippet then click Start collecting data. Follow the instructions in the image below.

Plausible Synology NAS Set up 13

  • STEP 20

Paste your personal JavaScript snippet that you have automatically generated at STEP 19 on your website between the <​head> and </head> tags of your site, then update your file. For example, I have a WordPress website hosted on a Synology NAS. If you have a WordPress website hosted elsewhere, know that the process is the same. Log into your WordPress admin Dashboard, click on the left sidebar on “Theme File Editor“, under Appearance. Select your theme then search for the header.php file. Paste your personal JavaScript snippet in the header.php file between the <​head> and </head> tags of your site, then update your file. Follow the instructions in the image below.
Note: You can add multiple websites via the Plausible Dashboard later.

Plausible Synology NAS Set up 14

Go back to your plausible synology.me DDNS and start looking at the stats! After the JavaScript snippet is added to your website, Plausible will start to collect Real-Time analytics of your website. My blog doesn’t have any TRACKING CODE on it. I just installed Plausible to show you how it works and how easily you can implement it on your website. I have already uninstalled it. Don’t forget to go back to STEP 1. I have worked hard for this guide so you can enjoy it.

Plausible Synology NAS Set up 15

Enjoy Plausible!

Note: Can I run Docker on my Synology NAS? See the supported models.
Note: Find out how to update the Plausible container with the latest image.
Note: How to Free Disk Space on Your NAS if You Run Docker.
Note: Instead of the synology.me DDNS you can also use your own domain name.
Note: How to Schedule Start & Stop For Docker Containers.
Note: How to Activate Email Notifications.
Note: How to Add Access Control Profile on Your NAS.
Note: How to Change Docker Containers Restart Policy.
Note: How to Use Docker Containers With VPN.
Note: Convert Docker Run Into Docker Compose.
Note: How to Clean Docker.
Note: How to Clean Docker Automatically.
Note: Best Practices When Using Docker and DDNS.
Note: Some Docker Containers Need WebSocket.
Note: Find out the Best NAS Models For Docker.
Note: Activate Gmail SMTP For Docker Containers.

This post was updated on Saturday / January 28th, 2023 at 5:48 PM