【问题标题】:Problems with POST parameters with Tomcat/AJP on Apache 2.4 (but not 2.2)Apache 2.4(但不是 2.2)上 Tomcat/AJP 的 POST 参数问题
【发布时间】:2017-10-25 08:36:15
【问题描述】:

我正在运行 Apache 2.4 和 Tomcat 7 的新机器上设置我们的 webapp 版本,但无法登录。当前站点在 Apache 2.2 和 Tomcat 6 上运行。

调试显示 request.getParameter() 仅在 2.4 站点上返回 null

我已经在所有浏览器中检查了这一点,并且可以在网站上导航,因此 AJP 至少可以部分正常工作 - 只有当我发布表单时,我的 Tomcat 看不到表单数据。

两者的配置相同:

<VirtualHost *:80>
  ServerName      www.example.com
  ServerAlias      example.com
  ServerAlias      cdn.example.com
  ServerAlias      prod.example.com

  ProxyPreserveHost On
  ProxyPass /images/ !
  ProxyPass /font/ !
  ProxyPass /style/ !
  ProxyPass / ajp://localhost:8009/ retry=1 acquire=3000 timeout=600 Keepalive=On
  ProxyPassReverse / ajp://localhost:8009/

server.xml 中定义的连接器为:

<Connector port="8009" address="localhost"
           maxThreads="250" minSpareThreads="5" maxSpareThreads="15"
           connectionTimeout="200000"
           packetSize="16384"
           maxHttpHeaderSize="16384"
           enableLookups="false" redirectPort="8443"
           emptySessionPath="true" URIEncoding="UTF-8" protocol="AJP/1.3"/>

浏览器请求头是:

Host: prod.example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:53.0) Gecko/20100101 Firefox/53.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es,sv;q=0.9,de;q=0.8,en;q=0.6,es-MX;q=0.5,en-AU;q=0.4,ja;q=0.3,fr;q=0.1
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 73
Referer: http://prod.example.com/en_US/auth/login.action
Cookie: JSESSIONID=07FB9E1A02A4464C0D65B332B53EF02F
Connection: keep-alive
Upgrade-Insecure-Requests: 1

我启用了通过端口 8080 直接访问 Tomcat,并且通过这种方式登录也可以正常工作。

代码来自同一个 git 存储库和分支,因此其他所有内容都应与旧站点相同。我应该研究 Tomcat 7 或 Apache 2.4 的变化来跟踪这个吗?

更新:我创建了一个非常简单的 test.jsp,并设置了一个要发布的表单。我用...

Enumeration paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
  String name = (String) paramNames.nextElement();
  String[] values = request.getParameterValues(name);

.. 转储参数。通过直接 8080 URL,这可以完美地工作,但是通过 Apache/AJP,所有 POST 参数都会被忽略,但是如果我手动将 GET 参数添加到 URL,例如。 ?test=123 这些工作正常。

更新 2:我将request.getReader() 的输出添加到我的test.jsp,并且我的 POST 数据在那里正确显示,例如t1=Some+text&amp;t2=Testingrequest.getParameter("t1") 仍然是 null。我一定错过了一些非常愚蠢的东西。

更新 3:我最初认为这是与 SSL 相关的,但现在设置了一个非 SSL 虚拟主机,这也有完全相同的问题。我的测试页有一个日期戳,所以它似乎不是缓存问题。

更新 4:我刚刚做了以下更改,允许正确处理表单 POST 数据:

# ProxyPass / ajp://localhost:8009/ retry=1 acquire=3000 timeout=600 Keepalive=On
# ProxyPassReverse / ajp://localhost:8009/
ProxyPass / http://localhost:8080/ retry=1 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse / http://localhost:8080/

那么,这看起来像 Apache 或 Tomcat 错误吗?

【问题讨论】:

    标签: apache tomcat7 apache2.4 ajp


    【解决方案1】:

    您的 POST 正文中有多少项? Tomcat 有这些的最大数量。 Tomcat 7 的默认值非常高,为 10,000。 AJP 似乎不可配置,尽管有几个参数是可配置的。请参阅以下内容:

    https://tomcat.apache.org/tomcat-7.0-doc/config/ajp.html

    关于你的问题,这篇文章似乎暗示,经过详尽的测试,它是 AJP(尽管作者的结论是它是 tomcat):http://tomcat.10.x6.nabble.com/Tomcat-looses-POST-parameters-td2067515.html。本质上,数据进入了AJP,并没有出现在Tomcat的第一个过滤器中。

    您不使用 HTTP 进行 ProxyPass 的任何原因?

    【讨论】:

    • 这甚至适用于微小的数据包——只有几个字符的输入文本。看起来它是 Tomcat 在通过 AJP 时没有正确处理表单数据 - 但是,这些字节仍然可以通过 request.getReader 获得。
    • 出于性能原因,希望将 ProxyPass 与 AJP(通过 HTTP)一起使用。
    猜你喜欢
    • 2014-06-16
    • 1970-01-01
    • 2016-01-31
    • 2016-02-01
    • 2018-03-31
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    相关资源
    最近更新 更多