Nginx + php fastcgi showing “No input file specified.” instead of 404

狂风中的少年 提交于 2019-12-12 01:52:43

问题


My problem i quite simple.

When I request a .php file that doesn't exist, I see "No input file specified.", instead of the 404 page that you would expect.

I get that i am passing all requests with the .php extension to php-fpm, and i guess that php-fpm returns "No input file specified." when the file does not exist(?). How do i fix this?

/etc/nginx/nginx.conf:

http {
    server {
            listen              443 ssl;
            server_name         smarthome.dk;
            ssl_certificate     /home/www/SmartHome/cert/ssl.crt;
            ssl_certificate_key /home/www/SmartHome/cert/ssl.key;
            ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers         HIGH:!aNULL:!MD5;
            keepalive_timeout   70;

            root /home/www/SmartHome/public_html;
            index index.php index.html;

            location / {
                    try_files $uri $uri/ /404.php?$args;
            }
            location ~ \.php$ {
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_intercept_errors on;
            }
    }

I have cgi.fix_pathinfo = 0; in /etc/php5/fpm/php.ini.


回答1:


I figured it out

You need to add try_files $uri $uri/ /404.php?$args; to location ~\.php$

No input file is specified because the file does not exist, and therefore is not passed. try_files $uri $uri/ /404.php?$args; checks that the file does actually exist, otherwise it redirects to 404.php



来源:https://stackoverflow.com/questions/41381122/nginx-php-fastcgi-showing-no-input-file-specified-instead-of-404

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!