【问题标题】:piwik docker image with nginx on subpath子路径上带有 nginx 的 piwik docker 映像
【发布时间】:2018-05-31 15:41:42
【问题描述】:

我已经成功地使用这个docker-compose.yml在nginx后面运行了piwiki:fpm容器:

version: '2'

services:
  analytics:
    image: piwik:fpm
    volumes:
      - ./config:/var/www/html/config:rw
      - ./logs:/var/www/html/logs
    env_file:
      - ./.matomo-env

  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
    links:
      - analytics
    volumes_from:
      - analytics

并使用此 nginx 配置:

upstream analytics {
  server analytics:9000;
}

server {
  listen 80;

  root /var/www/html/;
  index index.php index.html index.htm;

  location / {
    try_files $uri $uri/ =404;
  }

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root /usr/share/nginx/html;
  }

  location = /favicon.ico {
    log_not_found off;
    access_log off;
  }

  location ~ \.php$ {
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx;
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    fastcgi_intercept_errors on;
    fastcgi_pass analytics;
  }
}

现在,当我导航到http://localhost/ 时,它会很好地显示 piwik 界面。现在我想把它放在一个更复杂的环境中,根位置/ 不可用,所以我想使用/analytics。我尝试了location /analyticslocation ^~ /analytics 的可能组合,但页面从未出现过,什么是 nginx 配置可以工作?

【问题讨论】:

  • 请记住,现在 Piwik 已重命名为 matomo,docker 映像现在也称为 matomo。
  • 你做到了吗?
  • 不,我将其设置为子域

标签: docker nginx docker-compose matomo


【解决方案1】:

我来这里是为我的丑陋实现寻找更好的解决方案,如下所示:

来自我的 nginx 配置(来自服务器块):

    location = /matomo/index.php {                                              
        include fastcgi_params;                                                 
        fastcgi_param  SCRIPT_FILENAME    /var/www/html/index.php;              
        fastcgi_pass my-matomo:9000;                                     
    }                                                                           

    location = /matomo/piwik.php {                                              
        include fastcgi_params;                                                 
        fastcgi_param  SCRIPT_FILENAME    /var/www/html/piwik.php;              
        fastcgi_pass my-matomo:9000;                                     
    }                                                                           

    location /matomo {                                                          
        alias /var/www/html;                                                    

        try_files $uri @matomo;                                                 
    }                                                                           

    location @matomo {                                                          
        include fastcgi_params;                                                 
        fastcgi_param  SCRIPT_FILENAME    /var/www/html/index.php;              
        fastcgi_pass my-matomo:9000;                                     
    }                                                                           

否则与您的设置非常相似。

运行良好,但不是有史以来最整洁的 nginx 设置 :)

【讨论】:

  • 试过但收到client_1 | 2019/04/26 18:10:05 [error] 6#6: *5 no resolver defined to resolve matomo, client: 172.18.0.1, server: , request: "GET /matomo/index.php HTTP/1.1", host: "localhost" client_1 | 172.18.0.1 - - [26/Apr/2019:18:10:05 +0000] "GET /matomo/index.php HTTP/1.1" 502 157 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0" "-"
猜你喜欢
  • 1970-01-01
  • 2017-10-10
  • 1970-01-01
  • 2021-01-27
  • 1970-01-01
  • 2019-07-06
  • 2019-04-16
  • 2018-03-24
  • 2014-10-17
相关资源
最近更新 更多