NGINX - 未指定输入文件。 - php-fpm

时间:2017-08-30 10:32:11

标签: php nginx ubuntu-16.04

标题中描述了错误。 问题是.php文件都可以,但是我无法提供.html文件(403错误)。 Nginxphp-fpm的工作方式与www-data用户相同,所有网站目录的所有者组为www-data,我正在测试的文件的权限为775。

如果我将index.html重命名为index.php,那么一切正常。

我的虚拟主机配置:

server {
    listen 80;
    server_name www.martynov.test.kooweb.ru martynov.test.kooweb.ru;
    root /home/martynov/www/test.kooweb.ru;
    access_log /var/log/nginx/martynov.test.kooweb.ru.access.log;
    index index.html index.htm index.php;

    location / {
            try_files $uri $uri/ /index.php;
    }

    # serve static files directly
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|map|coffee|svg)$ {
            access_log off;
            expires max;
    }

    location ~ /\.ht {
            deny  all;
    }

    location ~* \.php {
            try_files $uri =404;
            include common/php-fpm;
    }
}

common / php-fpm包含:

fastcgi_pass    php-fpm;
include fastcgi_params;
fastcgi_split_path_info                 ^(.+?\.php)(/.*)?$;
fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
fastcgi_param   PATH_TRANSLATED         $document_root$fastcgi_script_name;
set             $path_info              $fastcgi_path_info;
fastcgi_param   PATH_INFO               $path_info;
fastcgi_param   SERVER_ADMIN            email@example.com;
fastcgi_param   SERVER_SIGNATURE        nginx/$nginx_version;
fastcgi_index   index.php;

版本:

  • Ubuntu版本16.04
  • Nginx版本1.12.1
  • Php版本7.1

UPD 有一些消息被添加到nginx错误日志中:

  1. 当我尝试访问/show5/地址
  2. [error] 26452#26452: *275 FastCGI sent in stderr: "Unable to open primary script: <directory>/show5/index.php (No such file or directory)" while reading response header from upstream, client: <ip>, server: <server>, request: "GET /show5/ HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.1-fpm.sock:", host: "<domain>"

    1. 当我尝试访问/show5/index.html地址
    2. [error] 26452#26452: *278 FastCGI sent in stderr: "Access to the script '<directory>/show5/index.html' has been denied (see security.limit_extensions)" while reading response header from upstream, client: <ip>, server: <server>, request: "GET /show5/index.html HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.1-fpm.sock:", host: "<domain>"

      我不知道如何解决这个问题。

2 个答案:

答案 0 :(得分:0)

添加额外的块

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

或者如果您只是想从html文件中获取它,那么将其添加如下

location ~* \.html {
   try_files $uri $uri/ =404;
}

答案 1 :(得分:0)

很明显,即使在您不想要的情况下,您也会匹配.php位置区块。我在这里看到了几件事:

 index index.php index.html index.htm;

这些按照外观顺序进行尝试。所以nginx会在/foo/index.html之前尝试重写/foo/index.php。

我建议你将index.php移到该列表的后面。

 index index.html index.htm index.php;

在.php位置块中,这是奇怪的:

 location ~* \.php {
        try_files $1 $uri $uri/ $uri/index.php    =404;
        include common/php-fpm;
 }

你正在尝试一些奇怪的东西,比如/foo/bar.php/和/foo/bar.php/index.php没有明显的原因,考虑到位置块已经进入这个位置,因为它匹配了{{1} }。我建议将其简化为:

something.php