piwik码头图像与子路径上的nginx

时间:2018-05-31 15:41:43

标签: docker nginx docker-compose matomo

我已成功设法运行piwiki:fpm容器,使用此docker-compose.yml在nginx后面使用docker compose:

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配置会起作用吗?

1 个答案:

答案 0 :(得分: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设置:)