NGINX Unit

Matomo§

要使用 Unit 运行 Matomo Web 分析平台

  1. 使用 PHP 语言模块安装 Unit

  2. 安装和配置 Matomo 的 先决条件

  3. 安装 Matomo 的 核心文件。在此,我们将其安装在 /path/to/app/;在配置中使用实际路径。

  4. 运行以下命令,以便 Unit 可以访问 应用程序目录

    # chown -R unit:unit /path/to/app/
    

    注意

    unit:unit 用户组对仅适用于 官方软件包、Docker 镜像 和一些 第三方仓库。否则,帐户名称可能有所不同;运行 ps aux | grep unitd 命令以确保这一点。

    有关更多详细信息(包括权限),请参阅 安全检查清单

  5. 接下来,准备 Unit 的 Matomo 配置(对 shareroot 使用实际值)。Matomo 安装中的默认 .htaccess 方案大致转换为以下内容

    {
        "listeners": {
            "*:80": {
                "pass": "routes"
            }
        },
    
        "routes": [
            {
                "match": {
                    "uri": [
                        "/index.php",
                        "/js/index.php",
                        "/matomo.php",
                        "/misc/cron/archive.php",
                        "/piwik.php",
                        "/plugins/HeatmapSessionRecording/configs.php"
                    ]
                },
    
                "action": {
                    "pass": "applications/matomo/direct"
                }
            },
            {
                "match": {
                    "uri": [
                        "*.php",
                        "*/.htaccess",
                        "/config/*",
                        "/core/*",
                        "/lang/*",
                        "/tmp/*"
                    ]
                },
    
                "action": {
                    "return": 404
                }
            },
            {
                "match": {
                    "uri": "~\\.(css|gif|html?|ico|jpg|js(on)?|png|svg|ttf|woff2?)$"
                },
    
                "action": {
                    "share": "/path/to/app$uri"
                }
            },
            {
                "match": {
                    "uri": [
                        "!/libs/*",
                        "!/node_modules/*",
                        "!/plugins/*",
                        "!/vendor/*",
                        "!/misc/cron/*",
                        "!/misc/user/*"
                    ]
                },
    
                "action": {
                    "share": "/path/to/app$uri",
                    "fallback": {
                        "pass": "applications/matomo/index"
                    }
                }
            }
        ],
    
        "applications": {
            "matomo": {
                "type": "php",
                "targets": {
                    "direct": {
                        "root": "/path/to/app/"
                    },
    
                    "index": {
                        "root": "/path/to/app/",
                        "script": "index.php"
                    }
                }
            }
        }
    }
    
  6. 上传更新的配置。假设上述 JSON 已添加到 config.json

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock https://#/config/
    

    注意

    控制套接字 路径可能有所不同;运行 unitd -h 或参阅 启动和关闭 了解详情。

    成功更新后,Matomo 应可在侦听器的 IP 地址和端口上使用

    Matomo on Unit