Apache 2.4 + php-fpm - AH01071:出现错误“主脚本未知\n”mod_proxy_balancer

Posted

技术标签:

【中文标题】Apache 2.4 + php-fpm - AH01071:出现错误“主脚本未知\\n”mod_proxy_balancer【英文标题】:Apache 2.4 + php-fpm - AH01071: Got error 'Primary script unknown\n' mod_proxy_balancerApache 2.4 + php-fpm - AH01071:出现错误“主脚本未知\n”mod_proxy_balancer 【发布时间】:2014-08-05 11:03:02 【问题描述】:

我正在我的 Ubuntu 14.04 中使用 php-fpm 5.5.9 配置 Apache 2.4.9。我想要的是为 php-fpm 请求做一个平衡器,但它会引发以下错误:

AH01071: Got error 'Primary script unknown\n'

当我尝试访问我的 php 文件时。代理平衡器似乎没有抓取 ProxyPassMatch 传递给它的文档根。我正在使用 UDS 让 apache 访问 php-fpm 套接字,而不是使用网络 tcp。

如果我在没有平衡器的情况下配置它,一切正常。

作品

ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/run/php5-fpm.sock1|fcgi://./var/www/html

不工作

ProxyPassMatch ^/(.*\.php(/.*)?)$ balancer://localhost/var/www/html
<Proxy balancer://localhost/>
    BalancerMember unix:/var/run/php5-fpm.sock1|fcgi://localhost:9001
    BalancerMember unix:/var/run/php5-fpm.sock2|fcgi://localhost:9002
    BalancerMember unix:/var/run/php5-fpm.sock3|fcgi://localhost:9003
    BalancerMember unix:/var/run/php5-fpm.sock4|fcgi://localhost:9004
</Proxy>

这是平衡器的配置日志:

[Sun Jun 15 12:32:30.839726 2014] [authz_core:debug] [pid 12217:tid 140330025703168] mod_authz_core.c(828): [client 10.1.1.2:52526] AH01628: authorization result: granted (no directives)
[Sun Jun 15 12:32:30.839899 2014] [lbmethod_byrequests:debug] [pid 12217:tid 140330025703168] mod_lbmethod_byrequests.c(97): AH01207: proxy: Entering byrequests for BALANCER (balancer://localhost)
[Sun Jun 15 12:32:30.839915 2014] [lbmethod_byrequests:debug] [pid 12217:tid 140330025703168] mod_lbmethod_byrequests.c(144): AH01208: proxy: byrequests selected worker "fcgi://localhost:9001" : busy 0 : lbstatus -3
[Sun Jun 15 12:32:30.839929 2014] [proxy_balancer:debug] [pid 12217:tid 140330025703168] mod_proxy_balancer.c(616): [client 10.1.1.2:52526] AH01172: balancer://localhost: worker (fcgi://localhost:9001) rewritten to fcgi://localhost:9001/var/www/html/info.php
[Sun Jun 15 12:32:30.839942 2014] [proxy:debug] [pid 12217:tid 140330025703168] proxy_util.c(1761): AH00924: worker unix:/var/run/php5-fpm.sock1|fcgi://localhost:9001 shared already initialized
[Sun Jun 15 12:32:30.839958 2014] [proxy:debug] [pid 12217:tid 140330025703168] proxy_util.c(1808): AH00927: initializing worker unix:/var/run/php5-fpm.sock1|fcgi://localhost:9001 local
[Sun Jun 15 12:32:30.840004 2014] [proxy:debug] [pid 12217:tid 140330025703168] proxy_util.c(1843): AH00930: initialized pool in child 12217 for (localhost) min=0 max=25 smax=25
[Sun Jun 15 12:32:30.840018 2014] [proxy:debug] [pid 12217:tid 140330025703168] mod_proxy.c(1138): [client 10.1.1.2:52526] AH01143: Running scheme balancer handler (attempt 0)
[Sun Jun 15 12:32:30.840039 2014] [proxy_fcgi:debug] [pid 12217:tid 140330025703168] mod_proxy_fcgi.c(768): [client 10.1.1.2:52526] AH01076: url: fcgi://localhost:9001/var/www/html/info.php proxyname: (null) proxyport: 0
[Sun Jun 15 12:32:30.840058 2014] [proxy_fcgi:debug] [pid 12217:tid 140330025703168] mod_proxy_fcgi.c(775): [client 10.1.1.2:52526] AH01078: serving URL fcgi://localhost:9001/var/www/html/info.php
[Sun Jun 15 12:32:30.840090 2014] [proxy:debug] [pid 12217:tid 140330025703168] proxy_util.c(2094): AH00942: FCGI: has acquired connection for (localhost)
[Sun Jun 15 12:32:30.840102 2014] [proxy:debug] [pid 12217:tid 140330025703168] proxy_util.c(2108): AH02545: FCGI: has determined UDS as /var/run/php5-fpm.sock1
[Sun Jun 15 12:32:30.840115 2014] [proxy:debug] [pid 12217:tid 140330025703168] proxy_util.c(2169): [client 10.1.1.2:52526] AH00944: connecting fcgi://localhost:9001/var/www/html/info.php to localhost:9001
[Sun Jun 15 12:32:30.840134 2014] [proxy:debug] [pid 12217:tid 140330025703168] proxy_util.c(2304): [client 10.1.1.2:52526] AH00947: connected /var/www/html/info.php to localhost:9001
[Sun Jun 15 12:32:30.840272 2014] [authz_core:debug] [pid 12217:tid 140330025703168] mod_authz_core.c(828): [client 10.1.1.2:52526] AH01628: authorization result: granted (no directives)
[Sun Jun 15 12:32:30.842988 2014] [proxy_fcgi:error] [pid 12217:tid 140330025703168] [client 10.1.1.2:52526] AH01071: Got error 'Primary script unknown\n'
[Sun Jun 15 12:32:30.843095 2014] [proxy:debug] [pid 12217:tid 140330025703168] proxy_util.c(2132): AH00943: FCGI: has released connection for (localhost)
[Sun Jun 15 12:32:30.843134 2014] [proxy_balancer:debug] [pid 12217:tid 140330025703168] mod_proxy_balancer.c(670): [client 10.1.1.2:52526] AH01176: proxy_balancer_post_request for (balancer://localhost)
[Sun Jun 15 12:32:30.978315 2014] [authz_core:debug] [pid 12217:tid 140330017310464] mod_authz_core.c(802): [client 10.1.1.2:52526] AH01626: authorization result of Require all granted: granted
[Sun Jun 15 12:32:30.978346 2014] [authz_core:debug] [pid 12217:tid 140330017310464] mod_authz_core.c(802): [client 10.1.1.2:52526] AH01626: authorization result of <RequireAny>: granted
[Sun Jun 15 12:32:30.978387 2014] [core:info] [pid 12217:tid 140330017310464] [client 10.1.1.2:52526] AH00128: File does not exist: /var/www/html/favicon.ico

【问题讨论】:

你检查过这里吗? serverfault.com/questions/450628/… 【参考方案1】:

tcpdump 在这种情况下会很有帮助。

tcpdump port 9001 -A | strings

它会告诉你 apache 试图在哪里找到你的主文件

【讨论】:

感谢它为我节省了几个小时寻找明显的东西:)(我的 fcgi 路径很糟糕 :)) 在我的情况下,请求是通过非默认接口处理的,并且未列出,使用此修复程序:tcpdump port 9001 -A -i any | strings

以上是关于Apache 2.4 + php-fpm - AH01071:出现错误“主脚本未知\n”mod_proxy_balancer的主要内容,如果未能解决你的问题,请参考以下文章

AH01630:客户端被服务器配置拒绝,但要求所有已设置(Apache 2.4,CentOs)

403 禁止,仅限 CakePHP - PHP-FPM - Apache 2.4 和 mod_proxy_fcgi

Apache 2.4 和 php-fpm 不会为 php 页面触发 apache http 基本身份验证

如何在centos 7上执行html文件(php-fpm和apache 2.4)中的php代码

如何通过 unix socket 设置 Apache2 和 PHP-FPM?

Apache代理fcgi错误