找回密码
 新建账号

mod_proxy_fcgi No input file specified SCRIPT_FILENAME has a starting slash

[复制链接]
php 发表于 2019/5/28 12:02 | 显示全部楼层 |阅读模式
Apache httpd mod_proxy_fcgi php-cgi.exe No input file specified is very common when you try to use Apache HTTP Server's proxy_fcgi_module with PHP or other excutables as a CGI application to handle the FastCGI protocol on Windows systems.

mod_proxy_fcgi sets wrong SCRIPT_FILENAME with a starting slash, and the leading slash leads to a 404 error with a message No input file specified, as the FastCGI application php-cgi.exe doesn't know the right file path of the wrong-set SCRIPT_FILENAME which has a slash prefix.
  1. LogLevel crit proxy_module:trace8 proxy_fcgi_module:trace8
复制代码
Set mod_proxy_fcgi's loglevel to trace 8, in Apache HTTP Server's error log file, we'll find that the env variable SCRIPT_FILENAME has a leading slash, which is not expected and should be removed.
  1. mod_proxy_fcgi.c(385): [client 127.0.0.1:50162] AH01062: sending env var 'SCRIPT_FILENAME' value '/D:/Web/www/www.wuxiancheng.cn/index.php'
复制代码
  1. <VirtualHost *:80>
  2.         ServerName www.wuxiancheng.cn
  3.         DocumentRoot "D:/Web/www/www.wuxiancheng.cn"
  4.         <FilesMatch "\.php$">
  5.                 ProxyFCGIBackendType GENERIC
  6.                 SetHandler "proxy:fcgi://127.0.0.1:9981/"
  7.                 ProxyFCGISetEnvIf "reqenv('SCRIPT_FILENAME') =~ m#^/?(.*)$#" SCRIPT_FILENAME "$1"
  8.         </FilesMatch>
  9. </VirtualHost>
复制代码
We can reset the SCRIPT_FILENAME env variable by removing the leading slash with regular expression.
  1. php-cgi.exe -b 127.0.0.1:9981
复制代码
Now after starting php-cgi.exe, we restart Apache httpd, and the No input file specified error is gone.
We can also set other env variables using the ProxyFCGISetEnvIf directive.
I am using Apache httpd 2.4.39 and PHP 7.3.5 on Windows 7.
ProxyFCGIBackendType is introduced in Apache HTTP Server 2.4.26, if you're on previous versions of Apache httpd, you shoud comment out or remove this directive.

手机版|轻松E站

GMT+8, 2024/12/21 22:35

快速回复 返回顶部 返回列表