我正在尝试使用 apache 配置反向代理,但是出现了一个No protocol handler was valid for the URL
我无法理解的错误。
这是apache的相关配置:
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /gonvaled/examples/jsonrpc/output/services/ http://localhost:8000/services/
ProxyPassReverse /gonvaled/examples/jsonrpc/output/services/ http://localhost:8000/services/
请求到达 Apache 时为:
POST /gonvaled/examples/jsonrpc/output/services/EchoService.py HTTP/1.1
它们应该被转发到我的内部服务,位于:
0.0.0.0:8000/services/EchoService.py
这些是日志:
==> /var/log/apache2/error.log <==
[Wed Jun 20 02:05:20 2012] [debug] proxy_util.c(1506): [client 127.0.0.1] proxy: http: found worker http://localhost:8000/services/ for http://localhost:8000/services/EchoService.py, referer: http://localhost/gonvaled/examples/jsonrpc/output/JSONRPCExample.safari.cache.html
[Wed Jun 20 02:05:20 2012] [debug] mod_proxy.c(998): Running scheme http handler (attempt 0)
[Wed Jun 20 02:05:20 2012] [warn] proxy: No protocol handler was valid for the URL /gonvaled/examples/jsonrpc/output/services/EchoService.py. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
[Wed Jun 20 02:05:20 2012] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 614 to 373 : URL /gonvaled/examples/jsonrpc/output/services/EchoService.py, referer: http://localhost/gonvaled/examples/jsonrpc/output/JSONRPCExample.safari.cache.html
==> /var/log/apache2/access.log <==
127.0.0.1 - - [20/Jun/2012:02:05:20 +0200] "POST /gonvaled/examples/jsonrpc/output/services/EchoService.py HTTP/1.1" 500 598 "http://localhost/gonvaled/examples/jsonrpc/output/JSONRPCExample.safari.cache.html" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19"
答案1
我找到了问题所在。该proxy_http
模块也需要在 Apache 中激活(我只有proxy_html
和proxy
)
答案2
对我来说,在 apache 上httpd 2.4
,发生这种情况是因为我缺少尾随斜杠:
不工作:
<Proxy balancer://mycluster>
BalancerMember http://192.168.111.7
BalancerMember http://192.168.111.80
</Proxy>
ProxyPass / balancer://mycluster
ProxyPassReverse / balancer://mycluster
有效!
<Proxy balancer://mycluster>
BalancerMember http://192.168.111.7
BalancerMember http://192.168.111.80
</Proxy>
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
(/
最后添加)
答案3
对于那些寻找答案的人来说,另一种可能性是后端的 URL 服务名称也丢失了。使用 LogLevel Debug、mod_proxy 和 mod_proxy_fcgi,我看到了以下内容:
[debug] proxy: fgci: found worker fgci://127.0.0.1:9000/var/www/html/.../index.php [debug] mod_proxy.c(1026): Running scheme fgci handler (attempt 0) [debug] mod_proxy_fcgi.c(800): [client ...] AH01076: url: fgci://127.0.0.1:9000/var/www/html/.../index.php proxyname: (null) proxyport: 0 [debug] mod_proxy_fcgi.c(805): [client ...] AH01077: declining URL fgci://127.0.0.1:9000/var/www/html/.../index.php [warn] proxy: No protocol handler was valid for the URL /.../index.php. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
值得庆幸的是,mod_proxy_fastcgi 的代码(我在 RHEL6 上使用 Apache 2.2 的反向移植)可以在以下位置找到:https://github.com/ceph/mod-proxy-fcgi/blob/master/mod_proxy_fcgi.c#L805,也就是这段代码:
if (strncasecmp(url, "fcgi:", 5) != 0) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01077) "declining URL %s", url);
return DECLINED;
}
如果你仔细查看日志——我在查看发出消息的代码时才注意到这一点——你会发现拼写错误fcgi://...
为fgci://...
因此,当您看到declining URL
它时,意味着:
- 您没有加载接受服务的处理程序(例如 fcgi:),或者
- 您拼错了服务名称。