我将其添加到我的 .htaccess 文件中:
AddHandler fcgid-script .test
(我正在使用 FastCGI/VirtualMin/WebMin)
并用内容创建了一个 test.test 文件;
<?php echo "test"; ?>
这会导致内部服务器错误,并在错误日志中显示此消息:
[Thu Apr 16 14:12:57.631287 2015] [fcgid:warn] [pid 2646] (104)Connection reset by peer: [client xxxx:53595] mod_fcgid: error reading data from FastCGI server
[Thu Apr 16 14:12:57.631402 2015] [core:error] [pid 2646] [client xxxx:53595] End of script output before headers: test.test
我做错了什么?我尝试使用不同的处理程序名称,例如 x-httpd-php 或 x-httpd-php5,但这根本没有任何作用。
我也试过:
<FilesMatch "\.test$">
SetHandler fcgid-script
</FilesMatch>
但它有相同的内部服务器错误。
最佳答案
FastCGId 模块似乎不知道如何执行您的脚本 - FcgidWrapper似乎缺少指令(因为您的 PHP 脚本没有 Shebang )。
根据您的发行版,您必须手动设置它,或者您可以调整已经处理 .php 文件的现有指令以也处理 .test 文件(通常这应该使用“SetHandler fcgid-script”指令和设置来完成/复制 FcgidWrapper 指令)。
调整后的示例(取自 https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#examples):
<FilesMatch "\.test$">
AddHandler fcgid-script .test
</FilesMatch>
Options +ExecCGI
FcgidWrapper /usr/bin/php5-cgi .test
更多信息和示例:https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#examples和 http://tltech.com/info/php-on-fcgid/
其他问题可能基于权限,例如如果您使用的是 suexec,则 fastcgid 进程无法写入日志或无法执行包装脚本。如果您能说明正常的 .php 文件是否正确执行,这将非常有帮助。
关于php - 使文件扩展名由 PHP 解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29691853/