Nginx 网站和Piwik在同一台服务器上生成403

Nginx 网站和Piwik在同一台服务器上生成403,nginx,matomo,Nginx,Matomo,我在xyz.com上有一个网站,在xyz.com/piwik上有一个piwik。Piwik运行良好,但不幸的是,并非所有Piwik请求的数据都由服务器处理 我看过这样的行为: xyz.com/piwik/->错误 xyz.com/piwik/index.php->可以 xyz.com/piwik/?模块=…->错误 nginx.conf # Configuration containing list of application servers upstream wsgi_cluster

我在xyz.com上有一个网站,在xyz.com/piwik上有一个piwik。Piwik运行良好,但不幸的是,并非所有Piwik请求的数据都由服务器处理

我看过这样的行为:

xyz.com/piwik/->错误

xyz.com/piwik/index.php->可以

xyz.com/piwik/?模块=…->错误

nginx.conf

    # Configuration containing list of application servers
upstream wsgi_cluster {
        server ***.***.112.44:5000;
}

# Default server configuration
#
server {
    listen 80;
    error_log /var/log/nginx/http.error.log warn;
    server_name xxx;
    return 301 https://$server_name$request_uri;
}

# HTTPS server
server {
  listen 443 ssl;
  server_name xxx;

  auth_basic "Restricted";

  root /usr/share/nginx/html;
  index index.html index.htm;

  ssl on;
  ssl_certificate /etc/nginx/ssl/server.crt;
  ssl_certificate_key /etc/nginx/ssl/server.key;
  error_log /var/log/nginx/https.error.log warn;

  charset utf-8;

  location /piwik/ {
    location ~ /piwik/(.*\.php)(/.*)?$ {
      fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
    #fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #fastcgi_pass unix:/var/run/php5-fpm.sock;
    #fastcgi_index index.php;
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
  }



  location / {
    proxy_set_header        Host $http_host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;

    client_max_body_size    10m;
    client_body_buffer_size 128k; 
    proxy_connect_timeout   60s;
    proxy_send_timeout      90s;
    proxy_read_timeout      90s;
    proxy_buffering         off;
    proxy_temp_file_write_size 64k;
    proxy_pass http://wsgi_cluster;
    proxy_redirect          off;
  }

  # Deny certain User-Agents (case insensitive)
  # The ~* makes it case insensitive as opposed to just a ~
  if ($http_user_agent ~* "Baiduspider|Jullo|AcoiRobot" ) {
    return 403;
  }

  error_page 502 /502.html;
  location = /502.html {
    root /etc/nginx/;
    internal;
  }

  error_page 401 /401.html;
  location = /401.html {
    root /etc/nginx/;
    internal;
  }

}
my-site.conf

    # Configuration containing list of application servers
upstream wsgi_cluster {
        server ***.***.112.44:5000;
}

# Default server configuration
#
server {
    listen 80;
    error_log /var/log/nginx/http.error.log warn;
    server_name xxx;
    return 301 https://$server_name$request_uri;
}

# HTTPS server
server {
  listen 443 ssl;
  server_name xxx;

  auth_basic "Restricted";

  root /usr/share/nginx/html;
  index index.html index.htm;

  ssl on;
  ssl_certificate /etc/nginx/ssl/server.crt;
  ssl_certificate_key /etc/nginx/ssl/server.key;
  error_log /var/log/nginx/https.error.log warn;

  charset utf-8;

  location /piwik/ {
    location ~ /piwik/(.*\.php)(/.*)?$ {
      fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
    #fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #fastcgi_pass unix:/var/run/php5-fpm.sock;
    #fastcgi_index index.php;
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
  }



  location / {
    proxy_set_header        Host $http_host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;

    client_max_body_size    10m;
    client_body_buffer_size 128k; 
    proxy_connect_timeout   60s;
    proxy_send_timeout      90s;
    proxy_read_timeout      90s;
    proxy_buffering         off;
    proxy_temp_file_write_size 64k;
    proxy_pass http://wsgi_cluster;
    proxy_redirect          off;
  }

  # Deny certain User-Agents (case insensitive)
  # The ~* makes it case insensitive as opposed to just a ~
  if ($http_user_agent ~* "Baiduspider|Jullo|AcoiRobot" ) {
    return 403;
  }

  error_page 502 /502.html;
  location = /502.html {
    root /etc/nginx/;
    internal;
  }

  error_page 401 /401.html;
  location = /401.html {
    root /etc/nginx/;
    internal;
  }

}

您缺少
/piwik/
URI的任何默认操作。如果没有找到其他匹配文件,您可能希望尝试使用
/piwik/index.php
URI。将
try\u files
指令添加到外部
位置
块,例如:

location /piwik/ {
    try_files $uri /piwik/index.php$is_args$args;

    location ~ /piwik/(.*\.php)(/.*)?$ { ... }
}

谢谢,但这只解决了从xyz.com/piwik/到xyz.com/piwik/index.php的匹配问题。调用xyz.com/piwik/?module=仍然不起作用。此调用的一个示例出现在所有网站的仪表板上,您可以在其中向项目中添加另一个网站。@TobiasK。更新应答以包含查询字符串。我不知道如何重写请求以使其正确传递。现在,我已经以某种方式编辑了我的nginx conf,我合并了location/piwik/{和location~\.php${,但是使用/piwik/?模块的请求仍然失败。@TobiasK。你试过上面的
/piwik/index.php$is_args$args
修复吗?很抱歉,我之前的评论可能有歧义。太棒了!这是缺少的部分。谢谢!