Installing Plausible for Website Analytics
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Plausible is a free and open source website analytics tool that does not rely on external services. Plausible allows you to track visitors, demographic data, device data, and much more. Plausible has a graphical interface that provides charts and maps that provide insight into the performance of your website server. Setting Plausible up on Akamai Connected Cloud and integrating it within your application is straightforward.
Before You Begin
If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode.
You need to generate an API Token.
Deploy a Docker Marketplace App. This includes creating your limited sudo user, your SSH public key, the previously generated API token, the domain you’d like to use and an email address, the preferred image, region, plan, and root password. There are additional options for opening ports to allow email, however this is only needed if you’ll be allowing others to register for this Plausible instance. Once ready click on Create Linode. The process will take about 5-10 minutes to complete.
You need a domain name configured in the DNS Manager. Create A/AAAA records pointing to the server hosting Docker.
sudo
. If you’re not familiar with the sudo
command, see the
Users and Groups guide.Cloning the Plausible Repository
After you created your Compute Instance, you can login via SSH via your local terminal. Once you login, update and upgrade your server.
sudo apt update && sudo apt upgrade -y
Now that your system is up to date, clone the repository from Plausible containing the Docker compose file and the configuration files.
git clone https://github.com/plausible/hosting cd hosting
Adding Required Configurations
There is a file called
plausible-conf.env
within the hosting folder. This contains the environmental variables for the Docker compose file. The most important variables to configure are theSECRET_KEY_BASE
and theBASE_URL
variables. You can generate a security key with the command below. openssl rand -base64 64 | tr -d '\n' ; echo
Use a tool such as nano or vim to edit the
plausible-conf.env
file. Add your domain to theBASE_URL
variable. For now, use the HTTP protocol rather than HTTPS. In a later section, you will change this after generating the proper SSL certification.Once you’ve added the URL and key, save the file.
Next, use nano or vim to open the
docker-compose.yml
file. Change any database passwords for security.
Deploying the Container
Using the command below, deploy the container.
sudo docker-compose up -d
With the container running, navigate to port 8000 on your domain name to ensure that your new Plausible website is up and running. For instance, if you had the domain example.com, you’d enter the following:
http://example.com:8000
If you see the Plausible website you, Plausible was deployed successfully.
Reverse Proxy and Certificate
Now, you need to set up NGINX server software and configure it to run your Plausible website.
Install NGINX with the command below.
sudo apt update sudo apt install nginx
Allow the ports 80 and 443 in NGINX.
sudo ufw allow "Nginx Full"
Create a configuration profile in the
/etc/nginx/sites-available/
directory. You can call this anything. The command below uses nano, but feel free to use your preferred editor. sudo nano /etc/nginx/sites-available/plausible.conf
Copy and paste the following configuration text into your empty configuration file. Be sure to change the
example.com
domain to the domain you wish to use. In this case do not include http or https. - File: /etc/nginx/sites-available/plausible.conf
1 2 3 4 5 6 7 8 9 10 11 12 13
server { listen 80; listen [::]:80; server_name example.com; access_log /var/log/nginx/plausible.access.log; error_log /var/log/nginx/plausible.error.log; location / { proxy_pass http://localhost:8000; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
Save the file and exit the editor. This configuration is for HTTP only. In the next step, when we acquire our SSL certificate, Certbot will implement HTTPS automatically.
The next command links this new configuration in
sites-available
tosites-enabled
. sudo ln -s /etc/nginx/sites-available/plausible.conf /etc/nginx/sites-enabled/
We can use a NGINX command to verify that the configuration is correct. After it says the test was successful, reload the NGINX service.
sudo nginx -t sudo systemctl reload nginx
Now that the service is reloaded, visit your website without the port to ensure the new configuration is working.
Adding a TLS (SSL) Certification with Certbot
Adding an SSL certificate to any website is an important step for both security and user confidence. Generating a TLS certificate for our NGINX proxy is straightforward.
First, install Certbot.
sudo apt install certbot python3-certbot-nginx
With the application installed, run Certbot with the domain name you have chosen. After running this command, there will be additional prompts.
sudo certbot --nginx -d your.domain.here
You’ll need to enter your email, accept Certbot’s terms of service, decide if you’d like to share your email, and then select if you’d like all HTTP traffic redirected to HTTPS. This is optional, but redirecting is generally a good idea.
If successful, you’ll see a “congratulations” message with some additional information. At this point, you should go back into your
plausible-conf.env
from earlier and change yourBASE_URL
so this reflects the domain being served over HTTPS.
Accessing Plausible and Additional Configuration
You’re done! You can now create your account, add your website, and retrieve the code snippet you will include on your website. When adding the code to your website, make sure it’s in a location that is visible on every page. This can be done with a plugin in WordPress or with the code injection on Ghost. The inclusion process will be slightly different for every platform and service. There are many more configuration options and changes you can make. For example, such as adding a variable to disable registration. Additionally, setting up email servers and notification was not covered in this article. For more options and advanced configuration, please check out Plausible’s official documentation.
This page was originally published on