We recommend you follow this tutorial using a Cost-Optimized Instance.
Running web analytics with Plausible on Ubuntu Linux
- plausible
- ubuntu
- analytics
Plausible Analytics is an open-source web analytics initiative driven by the goal of enhancing privacy in analytics. It offers the possibility to independently host the solution on Scaleway Instances, thereby decreasing reliance on and surveillance from AdTech-related tools.
This tool significantly contributes to the enhancement of site performance, with its analytics script weighing in at less than 1 KB. This is 45 times smaller than the size tag of a typical commercial analytics solution. Plausible Analytics is intentionally designed for self-hosting through Docker, providing you with control over your analytics setup.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- An SSH key
- An Instance running on Ubuntu Jammy Jellyfish (22.04 LTS)
- Log into your Instance using SSH:
ssh root@<your_scaleway_instance_ip>
- Update the
apt
package manager and upgrade the software already installed on your Instance to the latest available version.apt update && apt upgrade -y - Install the Docker GPG Key. This step is required to verify the validity of the Docker packages that you will install in a later step.
sudo mkdir -m 0755 -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- Configure Docker’s software repositories to be able to install the required software on your Instance.
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Update the packet manager, and install Docker and its dependencies using
apt
.apt update && apt install docker-ce docker-ce-cli docker-compose containerd.io docker-buildx-plugin docker-compose-plugin - Download and unpack the Plausible repository:
curl -L https://github.com/plausible/hosting/archive/master.tar.gz | tar -xzTip
If you have
git
installed on your machine, you can also clone the repository using the following command:git clone https://github.com/plausible/hosting - Enter the Plausible directory:
Two important files are located in the downloaded folder:cd hosting*
docker-compose.yml
- installs and orchestrates networking between your Plausible server, Postgres database, Clickhouse database (for stats), and an SMTP server. This file comes preconfigured with values for most setups. You can tweak it if required.plausible-conf.env
- configures the Plausible server itself. The full list of configuration options is available in the official documentation. - Generate a random 64-character secret key which will be used to secure the application. Run the following command to generate one and copy it into your computer’s clipboard.
openssl rand -base64 64 | tr -d '\n' ; echo
- Open the file in a text editor (e.g.
nano
) and set theSECRET_KEY_BASE
to the key you have generated in the previous step. Then set theBASE_URL
for your Instance. Optionally include a port, if no port is configured it will use the default port8000
.nano plausible-conf.env - Start the server.
docker-compose up -d
Configuring an Nginx reverse and caching proxy for Plausible
As Plausible supports only plain HTTP traffic by default, we will configure an Nginx reverse proxy to provide HTTPS with a Let’s Encrypt certificate to increase security and cache the analytics script for improved performance.
To carry out the following steps you need to have a (sub)domain pointing to your Instance and valid A and/or AAAA records configured for it.
- Install Nginx and Certbot using
apt
. Nginx is a versatile web server that we use as a proxy to protect Plausible from direct access to the application and Certbot is a tool to automate the issuing and renewal of TLS certificates by Let’s Encrypt.apt install nginx python3-certbot-nginx - Create a new Nginx configuration file for Plausible and edit it as follows. In our case, Plausible will be hosted at
plausible.example.com
. Remember to edit this to your own domain name.nano /etc/nginx/sites-available/plausible.example.com.confproxy_cache_path /var/cache/nginx/data/jscache levels=1:2 keys_zone=jscache:100m inactive=30d use_temp_path=off max_size=100m;server {listen 80;listen [::]:80;server_name plausible.example.com;access_log /var/log/nginx/plausible-access.log;error_log /var/log/nginx/plausible-error.log;location / {proxy_pass http://127.0.0.1:8000;}location = /js/script.js {# Change this if you use a different variant of the scriptproxy_pass http://localhost:8000/js/script.js;proxy_set_header Host plausible.example.com;proxy_ssl_server_name on;proxy_ssl_session_reuse off;# Tiny, negligible performance improvement. Very optional.proxy_buffering on;# Cache the script for 6 hours, as long as plausible.io returns a valid responseproxy_cache jscache;proxy_cache_valid 200 6h;proxy_cache_use_stale updating error timeout invalid_header http_500;# Optional. Adds a header to tell if you got a cache hit or missadd_header X-Cache $upstream_cache_status;}location = /api/event {proxy_pass http://localhost:8000/api/event;proxy_set_header Host plausible.example.com;proxy_ssl_server_name on;proxy_ssl_session_reuse off;proxy_buffering on;proxy_http_version 1.1;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header X-Forwarded-Host $host;}} - Test the configuration to ensure that it will function correctly:
nginx -t
- Enable the server block by symlinking:
ln -s /etc/nginx/sites-available/plausible.example.com.conf /etc/nginx/sites-enabled/plausible.example.com.conf
- Restart Nginx to enable the new configuration:
systemctl nginx restart
- Run
certbot
to obtain a TLS certificate for your domain name and let the application configure Nginx automatically.certbotTipFor more details on using Certbot, refer to our dedicated documentation.
- Open the file
docker-compose.yml
in a text editor and change the line- 8000:8000
to -127.0.0.1:8000:8000
. This prevents Plausible from being accessed remotely using HTTP on port 8000 which is a security concern. - Stop the application using
docker-compose stop
. Then bring it up again to apply the new configurationdocker-compose up
. - Open a web browser and point it to
https://plausible.example.com/
. The Plausible registration screen displays. Complete the form to create your account.During account generation, the snippet to add to your website displays. Add it to your site and Plausible starts running analytics on your visitors.
For more information about Plausible, refer to the official Plausible documentation.