Matomo 统计系统安装及配置

工具1年前 (2023)更新 Webmaster
595 0 0

Matomo 统计系统安装及配置
Matomo 是领先的 Free/Libre 开放分析平台。

Matomo 是一个功能齐全的基于PHP+Mysql的网站统计程序,您可以下载并安装在您自己的网络服务器上。 在五分钟的安装过程结束时,您将获得一段 JavaScript 代码。 只需将此标签复制并粘贴到您想要跟踪并实时访问分析报告的网站上即可。

Matomo 的目标是成为 Google Analytics 的免费软件替代品,目前已在超过 1,400,000 个网站上使用!

项目主页: https://wwww.webmaster.me/sites/1271.html


首先在项目主页:https://github.com/matomo-org/matomo/releases 查询最新的稳定版本号,目前是4.15.0。

git clone -b 4.15.0 --depth 1 https://github.com/matomo-org/matomo.git

git fetch origin tag 4.20.0 –no-tags –depth 1
git checkout 4.15.0

chmod -R a+w matomo/config matomo/tmp/ matomo/js/piwik.js

安装php composer:

curl -sS https://getcomposer.org/installer | php 
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer


composer install


cd plugins/Morpheus
rm -rf icons
git clone  https://github.com/matomo-org/matomo-icons.git icons


server {
    listen [::]:80; # remove this if you don't want Matomo to be reachable from IPv6
    listen 80;
    server_name matomo.example.com;
    # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
    location / {
        return 301 https://$host$request_uri;
server {
    listen [::]:443 ssl http2; # remove this if you don't want Matomo to be reachable from IPv6
    listen 443 ssl http2;
    server_name matomo.example.com; # list all domains Matomo should be reachable from
    access_log /var/log/nginx/matomo.access.log;
    error_log /var/log/nginx/matomo.error.log;

    ## uncomment if you want to enable HSTS with 6 months cache
    ## ATTENTION: Be sure you know the implications of this change (you won't be able to disable HTTPS anymore)
    #add_header Strict-Transport-Security max-age=15768000 always;

    ## replace with your SSL certificate
    ssl_certificate /etc/letsencrypt/live/matomo.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/matomo.example.com/privkey.pem;

    include ssl.conf; # if you want to support older browsers, please read through this file

    add_header Referrer-Policy origin always; # make sure outgoing links don't show the URL to the Matomo instance
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;

    root /var/www/matomo/; # replace with path to your matomo instance

    index index.php;

    ## only allow accessing the following php files
    location ~ ^/(index|matomo|piwik|js/index|plugins/HeatmapSessionRecording/configs)\.php$ {
        include snippets/fastcgi-php.conf; # fetch it from https://github.com/nginx/nginx/blob/master/conf/fastcgi.conf
        try_files $fastcgi_script_name =404; # protects against CVE-2019-11043. If this line is already included in your snippets/fastcgi-php.conf you can comment it here.
        fastcgi_param HTTP_PROXY ""; # prohibit httpoxy: https://httpoxy.org/
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; #replace with the path to your PHP socket file
        #fastcgi_pass; # uncomment if you are using PHP via TCP sockets (e.g. Docker container)

    ## deny access to all other .php files
    location ~* ^.+\.php$ {
        deny all;
        return 403;

    ## serve all other files normally
    location / {
        try_files $uri $uri/ =404;

    ## disable all access to the following directories
    location ~ ^/(config|tmp|core|lang) {
        deny all;
        return 403; # replace with 404 to not show these directories exist

    location ~ /\.ht {
        deny  all;
        return 403;

    location ~ js/container_.*_preview\.js$ {
        expires off;
        add_header Cache-Control 'private, no-cache, no-store';

    location ~ \.(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2)$ {
        allow all;
        ## Cache images,CSS,JS and webfonts for an hour
        ## Increasing the duration may improve the load-time, but may cause old files to show after an Matomo upgrade
        expires 1h;
        add_header Pragma public;
        add_header Cache-Control "public";

    location ~ ^/(libs|vendor|plugins|misc|node_modules) {
        deny all;
        return 403;

    ## properly display textfiles in root directory
    location ~/(.*\.md|LEGALNOTICE|LICENSE) {
        default_type text/plain;

Matomo 统计系统安装及配置

如果你的站点接入了Cloudflare ,可以使用Cloudflare的APP进行统计,步骤参考:https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-cloudflare-setup/


1、将php.ini的memory_limit 值设置为 512M以上。

Matomo 统计系统安装及配置
5 * * * * /usr/bin/php /path/to/matomo/console core:archive --url=http://example.org/matomo/ > /dev/null

browser_archiving_disabled_enforce = 1

© 版权声明