如何通过 nginx Ubuntu 上的子页面访问 matomo

如何解决如何通过 nginx Ubuntu 上的子页面访问 matomo

我使用的是配置了 Nginx 的 Ubuntu 18.04.5 LTS 网络服务器。服务器正在运行,我可以访问我的主页 example.com 上的任何文件。现在我想在服务器上安装 matomo。但是,我只能设法通过我的根 url www.example.com 访问安装。每当我尝试将 matomo 访问移动到子页面时,例如example.com/matomo/ 我的服务器改为发送 404。我想我在创建用于调用页面的配置设置时犯了一个错误,但我无法弄清楚出了什么问题。我是 Nginx 的新手,过去 2 天一直在测试解决方案。任何帮助将不胜感激。请找到我的 server.conf,以及下面的 matomo.conf。

我的服务器配置文件如下:

server {
    listen                  443 ssl http2;
    listen                  [::]:443 ssl http2;
    server_name             www.example.com;
    set                     $base /var/www/example.com;
    root                    $base/public;

    # SSL
    ssl_certificate         /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key     /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;

    # security
    include                 Nginxconfig.io/security.conf;

    # logging
    access_log              /var/log/Nginx/example.com.access.log;
    error_log               /var/log/Nginx/example.com.error.log warn;

    # index.PHP
    index                   index.PHP;

    # index.PHP fallback
    location / {
        try_files $uri $uri/ /index.PHP?$query_string;
    }

    # handle .PHP
    location ~ \.PHP$ {
        fastcgi_pass unix:/var/run/PHP/PHP7.2-fpm.sock;
        include      Nginxconfig.io/PHP_fastcgi.conf;
    }
} 

我的 matomo.conf:

server {
    listen 443 ssl http2;
    server_name www.example.com/subpage example.com/subpage; 
    access_log /var/log/Nginx/matomo.access.log;
    error_log /var/log/Nginx/matomo.error.log;


    ## SSL
    ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;

    add_header Referrer-Policy origin always; 
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;

    root /var/www/example.com/subpage/matomo/; # path to 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;
        fastcgi_param HTTP_PROXY ""; 
        fastcgi_pass unix:/var/run/PHP/PHP7.2-fpm.sock; 
    }

    ## 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|json)$ {
        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/user|node_modules) {
        deny all;
        return 403;
    }

    ## properly display textfiles in root directory
    location ~/(.*\.md|LEgalNOTICE|LICENSE) {
        default_type text/plain;
    }
}
# vim: filetype=Nginx

解决方法

感谢您的快速回复。

在进一步寻找解决方案后,我现在已经完成了这两项工作:我创建了一个子域,并通过将以下代码添加到 subdomain.config 来在子页面下启动 matomo。

location /matomo {    
root /var/www/subdomain.example.com/matomo;
}

我发现 this 是创建子域的绝佳教程。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?