Windows上的Apache mod_proxy_fcgi和PHP-FPM(php-cgi.exe)问题(未指定输入文件.) [英] Apache mod_proxy_fcgi and PHP-FPM (php-cgi.exe) issue (No input file specified.) on Windows
问题描述
以下是PHP-FPM(PHP 5.5)
The following is PHP-FPM (PHP 5.5)
php-cgi.exe -b 127.0.0.1:9000
以下是mod_proxy_fcgi(Apache 2.4)
The following is mod_proxy_fcgi (Apache 2.4)
第一种方式
<Files ~ "\.(php|phtml)$">
SetHandler "proxy:fcgi://127.0.0.1:9000/"
</Files>
第二种方式
<LocationMatch ^(.*\.(php|phtml))$>
ProxyPass fcgi://127.0.0.1:9000/$1
</LocationMatch>
第三种方式
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^([^\.]+\.(php|phtml))$ fcgi://127.0.0.1:9000/$1 [P,L]
</IfModule>
以上三种方式将得到错误未指定输入文件".有人知道为什么吗?我应该怎么解决这个问题?
The above three ways will get an error "No input file specified." Anybody know why? How should I do to solve this problem?
推荐答案
莫名其妙地,仅将尾随的/
更改为#
似乎可以解决问题:
Inexplicably, simply changing the trailing /
to a #
seems to fix the problem:
<Files ~ "\.(php|phtml)$">
SetHandler "proxy:fcgi://127.0.0.1:9000#"
</Files>
为了理解这一点,我将Apache设置为LogLevel debug
(为简洁起见,删除了时间戳记/模块/进程详细信息):
In trying to understand this I set Apache to LogLevel debug
(timestamp/module/process details removed for brevity):
-
使用
/
给出:
mod_proxy_fcgi.c(911): [client ::1:60730] AH01076: url: fcgi://127.0.0.1:9000/E:/test/webroot/test.php proxyname: (null) proxyport: 0
mod_proxy_fcgi.c(920): [client ::1:60730] AH01078: serving URL fcgi://127.0.0.1:9000/E:/test/webroot/test.php
proxy_util.c(2154): AH00942: FCGI: has acquired connection for (*)
proxy_util.c(2208): [client ::1:60730] AH00944: connecting fcgi://127.0.0.1:9000/E:/test/webroot/test.php to 127.0.0.1:9000
proxy_util.c(2417): [client ::1:60730] AH00947: connected /E:/test/webroot/test.php to 127.0.0.1:9000
使用#
给出:
mod_proxy_fcgi.c(911): [client ::1:60738] AH01076: url: fcgi://127.0.0.1:9000#E:/test/webroot/test.php proxyname: (null) proxyport: 0
mod_proxy_fcgi.c(920): [client ::1:60738] AH01078: serving URL fcgi://127.0.0.1:9000#E:/test/webroot/test.php
proxy_util.c(2154): AH00942: FCGI: has acquired connection for (*)
proxy_util.c(2208): [client ::1:60738] AH00944: connecting fcgi://127.0.0.1:9000#E:/test/webroot/test.php to 127.0.0.1:9000
proxy_util.c(2417): [client ::1:60738] AH00947: connected to 127.0.0.1:9000
关键的区别似乎在最后一行,第二个(有效)方法似乎没有记录任何内容作为传递给PHP进程的值.
The crucial difference appears to be in the last line, where the second (working) method doesn't appear to log anything as the value passed to the PHP process.
我很无奈地对此进行解释,并且找不到任何地方提及它. (也许比我更愿意勇敢地探究Apache和/或PHP源代码进行调查.)
I'm at a loss to explain this and can't find mention of it anywhere. (Perhaps a braver soul than I would be willing to delve into the Apache and/or PHP source to investigate.)
请注意,除了运行phpinfo()
之外,我还没有进行过测试,因此不建议将其用于生产服务器.
Note that I haven't tested this beyond running phpinfo()
so wouldn't recommend it for a production server.
编辑
Edit
这适用于PHP 7.0,但对于PHP 5.6,我仍然收到未指定输入文件"错误.
This works for PHP 7.0, but with PHP 5.6 I still get the 'No input file specified' error.
编辑2
Edit 2
并使用Apache 2.4.25,但不能使用最近发布的2.4.26!
And working with Apache 2.4.25, but not the recently released 2.4.26!
这似乎是CHANGES_2.4.26文件中明确提到的不兼容雷区:
This seems to be an incompatibility minefield that is explicitly mentioned in the CHANGES_2.4.26 file:
mod_proxy_fcgi:返回2.4.20及更早版本的离开行为 SCRIPT_FILENAME环境变量中的前缀"proxy:fcgi://" 默认.添加ProxyFCGIBackendType以允许后端类型为 指定,以便可以修复这些修复程序而不会影响 FPM. PR60576 [Eric Covener,Jim Jagielski]
mod_proxy_fcgi: Return to 2.4.20-and-earlier behavior of leaving a "proxy:fcgi://" prefix in the SCRIPT_FILENAME environment variable by default. Add ProxyFCGIBackendType to allow the type of backend to be specified so these kinds of fixups can be restored without impacting FPM. PR60576 [Eric Covener, Jim Jagielski]
文档已更新为反映以下内容:
The documentation has been updated to reflect this:
根据此伪指令的设置更改的值的一个示例是SCRIPT_FILENAME.历史上使用mod_proxy_fcgi时,SCRIPT_FILENAME的前缀为字符串"proxy:fcgi://".一些通用FastCGI应用程序会将其作为脚本输入读取,但是PHP-FPM会删除该前缀,然后记住它正在与Apache通讯.在2.4.21至2.4.25中,服务器自动剥离了该前缀,从而在某些情况下破坏了PHP-FPM检测和与Apache互操作的能力.
One example of values that change based on the setting of this directive is SCRIPT_FILENAME. When using mod_proxy_fcgi historically, SCRIPT_FILENAME was prefixed with the string "proxy:fcgi://". This variable is what some generic FastCGI applications would read as their script input, but PHP-FPM would strip the prefix then remember it was talking to Apache. In 2.4.21 through 2.4.25, this prefix was automatically stripped by the server, breaking the ability of PHP-FPM to detect and interoperate with Apache in some scenarios.
这篇关于Windows上的Apache mod_proxy_fcgi和PHP-FPM(php-cgi.exe)问题(未指定输入文件.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!