NGINX - 未指定输入文件。 - php-fpm
NGINX - No input file specified. - php-fpm
错误如标题所述。
问题是 .php 文件一切正常,但我无法提供 .html 文件(403 错误)。 Nginx
和 php-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 错误日志的消息:
- 当我尝试访问
/show5/
地址时
[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>"
- 当我尝试访问
/show5/index.html
地址时
[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>"
我不知道如何解决这个问题。
添加一个额外的块
location / {
try_files $uri $uri/ =404;
}
或者,如果您只想从 html 个文件中获取它,请像下面那样添加它
location ~* \.html {
try_files $uri $uri/ =404;
}
很明显,即使在您不想匹配的情况下,您也在匹配 .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 $uri $uri/ $uri/index.php =404;
include common/php-fpm;
}
您无缘无故地尝试了一些奇怪的事情,例如 /foo/bar.php/ 和 /foo/bar.php/index.php,考虑到位置块已进入此位置,因为它匹配 something.php
。我建议将其简化为:
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
include common/php-fpm;
}
错误如标题所述。
问题是 .php 文件一切正常,但我无法提供 .html 文件(403 错误)。 Nginx
和 php-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 错误日志的消息:
- 当我尝试访问
/show5/
地址时
[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>"
- 当我尝试访问
/show5/index.html
地址时
[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>"
我不知道如何解决这个问题。
添加一个额外的块
location / {
try_files $uri $uri/ =404;
}
或者,如果您只想从 html 个文件中获取它,请像下面那样添加它
location ~* \.html {
try_files $uri $uri/ =404;
}
很明显,即使在您不想匹配的情况下,您也在匹配 .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 $uri $uri/ $uri/index.php =404;
include common/php-fpm;
}
您无缘无故地尝试了一些奇怪的事情,例如 /foo/bar.php/ 和 /foo/bar.php/index.php,考虑到位置块已进入此位置,因为它匹配 something.php
。我建议将其简化为:
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
include common/php-fpm;
}