bet*_*eta 3 proxy virtualhost proxypass apache-2.2
我有一个 ProxyPass 配置为达到以下目的:在我的服务器上,我启动了一个服务,该服务提供一个 Rest-API 监听端口 7777。从客户端,我希望能够像这样调用这个 API: http://example.org/servicename/PARAMETER
对此 API 的完整调用应如下所示: HTTP PUT @ http://example.org/servicename/PARAMETER
(其中PARAMETER
是某个字符串)。在内部,这应该转换为以下网址:http://server.ip:7777/servicename/PARAMETER
只要 PARAMETER 不是这样的(!),一切都会按预期工作:(http://parameter.org
实际上我需要对其进行 URL 编码:)http%3A%2F%2Fparameter.org
。总而言之,电话是http://example.org/servicename/http%3A%2F%2Fparameter.org
将http://
在参数混淆阿帕奇导致在回复呼叫以下错误信息:
!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /servicename/http://parameter.org was not found on this server.</p>
<hr>
<address>Apache/2.2.22 (Debian) Server at example.org Port 80</address>
</body></html>
Run Code Online (Sandbox Code Playgroud)
http%3A%2F%2Fparameter.org
例如,如果我替换为test
,则一切正常。http://
参数中的不知何故混淆了apache。有没有办法让 apache 忽略它?
我目前对这个虚拟主机的配置如下所示:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example
ServerName example.org
ErrorLog /var/log/apache2/example_error.log
LogLevel warn
CustomLog /var/log/apache2/example_access.log combined
<IfModule mod_proxy.c>
ProxyRequests Off
ProxyPass / http://localhost:7777/
ProxyPassReverse / http://localhost:7777/
</IfModule>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
先决条件:
编辑1:
tail -f /var/log/apache2/example_access.log
产量
128.xxx.xxx.xxx - - [19/Aug/2015:16:53:17 +0200] "PUT /servicename/http%3A%2F%2Fparameter.org HTTP/1.1" 404 521 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36"
Run Code Online (Sandbox Code Playgroud)
在默认的 Apache 配置中,AllowEncodedSlashes指令设置为off。这意味着:“ ...AllowEncodedSlashes 指令允许在路径信息中使用包含编码路径分隔符 [...] 的 URL。使用默认值 Off,此类 URL 将被拒绝,并出现 404(未找到)错误…… ”
所以问题是 mod_proxy没有代理您基于 URL 的 POST 请求,因为 Apache 在 mod_proxy 采取行动之前拒绝它们(使用 404)。
另一个可能的问题与 URL 编码过程有关:您的 apache(前端)肯定会收到一个正确的 URL 编码字符串(您发送给它的字符串:http : //example.org/servicename/http%3A %2F%2Fparameter.org ),我希望它 (apache) 在内部处理相关的 POST 请求时对其进行 URL 解码。所以我希望 Apache 内部的 mod_proxy 会收到一个真实的 URL(未编码),我想知道在代理时它是否会执行 URL 编码循环。在官方的 ProxyPass 文档中,我看到:“通常,mod_proxy 将规范化 ProxyPassed URL。但这可能与某些后端不兼容,尤其是那些使用 PATH_INFO 的后端。可选的 nocanon 关键字会抑制这种情况,并将 URL 路径“raw”传递给后端。请注意,此关键字可能会影响后端的安全性,因为它删除了代理提供的针对基于 URL 的攻击的正常有限保护“,因此您还应该评估“nocanon”选项的使用情况。
这两个问题(AllowEncodedSlashes和nocanon)已在此 StackOverflow 问题中提到
归档时间: |
|
查看次数: |
10144 次 |
最近记录: |