访问不存在的URL时没有指定输入文件错误';带有.php扩展名的
我的NGINX配置有问题,当我访问一个扩展名为.php但不存在的URL时,我得到的不是404响应,而是一个“未指定输入文件”错误。下面是我的NGINX配置,有什么想法吗访问不存在的URL时没有指定输入文件错误';带有.php扩展名的,php,nginx,server-configuration,Php,Nginx,Server Configuration,我的NGINX配置有问题,当我访问一个扩展名为.php但不存在的URL时,我得到的不是404响应,而是一个“未指定输入文件”错误。下面是我的NGINX配置,有什么想法吗 html { # Compression # Enable Gzip compressed. gzip on; # Enable compression both for HTTP/1.0 and HTTP/1.1. gzip_http_version 1.1; # Comp
html {
# Compression
# Enable Gzip compressed.
gzip on;
# Enable compression both for HTTP/1.0 and HTTP/1.1.
gzip_http_version 1.1;
# Compression level (1-9).
# 5 is a perfect compromise between size and cpu usage, offering about
# 75% reduction for most ascii files (almost identical to level 9).
gzip_comp_level 5;
# Don't compress anything that's already small and unlikely to shrink much
# if at all (the default is 20 bytes, which is bad as that usually leads to
# larger files after gzipping).
gzip_min_length 128;
# Compress data even for clients that are connecting to us via proxies,
# identified by the "Via" header (required for CloudFront).
gzip_proxied any;
# Tell proxies to cache both the gzipped and regular version of a resource
# whenever the client's Accept-Encoding capabilities header varies;
# Avoids the issue where a non-gzip capable client (which is extremely rare
# today) would display gibberish if their proxy gave them the gzipped version.
gzip_vary on;
# Compress all output labeled with one of the following MIME-types.
gzip_types application/atom+xml application/x-javascript application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component;
}
server {
listen 80;
server_name www.example.com example.com;
return 301 https://example.com$request_uri;
}
server {
listen *:443 ssl;
server_name www.example.com;
return https://example.com$request_uri 301;
}
server {
listen 443 ssl;
server_name example.com;
root /home/example/default/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/default-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_param DB_PASSWORD "password";
fastcgi_param DB_USERNAME "user";
fastcgi_param DB_NAME "db";
fastcgi_param DB_HOST "localhost";
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
# Expire rules for static content
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
# access_log logs/static.log; # I don't usually include a static log
}
# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
add_header Cache-Control "public";
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
}
为方便起见,添加:
fastcgi_param SCRIPT_FILENAME $request_filename;
…到您的位置~\.php${
块应该可以解决此问题。php需要此变量等于要执行的php脚本的绝对文件系统路径,并且您想要的具体内容取决于您的配置。对于配置脚本\u文件名
的正确方法,没有一刀切的答案
此处讨论了可使用的一些变量:
对于给定的场景,您想要的确切内容取决于许多因素,例如是否映射到不是$document\u root
的目录,是否使用了fpm,等等
但对于您所描述的情况,我认为上述内容应该可以解决您的问题。谢谢您的回复,但遗憾的是,添加此声明恐怕无法解决问题。@GarethDaine为fpm启用错误日志记录,并为池设置
catch\u workers\u output=yes
,如果您还没有这样做的话。这应该会记录一条消息,该消息将我告诉你它正在寻找的路径。@GarethDaine你的try_files
声明应该会导致它总是找到一个文件来服务请求,或者通过/index.php
-你确定/index.php
存在吗?是的,index.php是存在的。该网站应该工作,并更正URI的工作,但我如果您访问了一个扩展名为.php的不存在的东西,它就会崩溃。@GarethDaine将在我的测试盒上启动一个服务器,并在午餐时(约2小时)试用