NGINX PHP FASTCGI多个位置(别名)问题



首次发布,并且对所有这些非常新。在这里发现了现有的指南很棒,但是努力努力工作。经过大量的反复试验,查找我的位置块当前看起来像这样 - 全局PHP已被删除并包含在我的位置块中。

第一个工作正常,第二个更改后的第二个没有显示403或未找到404,而是显示一个通用的字符串"找不到文件。"

我的nginx错误日志访问时显示以下内容:

2018/02/26 19:13:47 [错误] 25229#25229: *185968 fastcgi发送了 STDERR:从阅读响应标头的"主脚本未知" 上游,客户端:x.x.x.x,服务器:domain.co.uk,请求:" get/test/ http/1.1",上游:" fastcgi://unix:/run/php/php7.0-fpm.sock:",主机: " domain.co.uk"

我一直在这里查看有关不同的fastcgi_param script_filename参数的各种位和零件,但我无法让其中任何一个工作。任何建议都将不胜感激,因为我花了几个小时试图使它工作并设法取得了一些进步,但我认为这将是完成这项工作的最终任务。

我已经从别名中删除了try_files,因为我被告知效果不好(在此之前的403(,并将$ request_filename添加到我的fastcgi_param bu中,该bu并未停止此错误。

location ~ ^((?!/test).)*$ {
include /etc/nginx/mime.types;
    root /var/www/html/test;
    index index.php index.html index.htm;
    location ~ .php$ {
        root /var/www/html/test;
        try_files $uri =404;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
        fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

location ~ ^/test(.*)$ {
include /etc/nginx/mime.types;
    alias /var/www/html/test2/;
    index index.php index.html index.htm;
    location ~ .php$ {
        alias /var/www/html/test2/;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
        fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name$request_filename;
        include fastcgi_params;
    }
}

对您的conf进行调整。

  1. root /var/www/html/test;移动到第一个位置块之外。nginx陷阱
  2. alias替换为第二块root。根据nginx文档
  3. 在第二块中删除第二个别名。无论如何都是多余的
  4. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name$request_filename;删除$request_filename;在ServerFault上相同的错误

基本上看起来像

 server {
   root /var/www/html/test;
   location /test {
      include /etc/nginx/mime.types;
      root /var/www/html/test2/;
      index index.php index.html index.htm;
      location ~ .php$ {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
        fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
      }
   }
   location / {
      include /etc/nginx/mime.types;
      index index.php index.html index.htm;
      location ~ .php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
        fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
      }
   }

}

最新更新