Apache/Tomcat 错误 - 正在传送错误的页面 [英] Apache/Tomcat error - wrong pages being delivered

查看:26
本文介绍了Apache/Tomcat 错误 - 正在传送错误的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个错误让我发疯.我们有一台运行 Apache 和 Tomcat 的服务器,为多个不同的站点提供服务.通常服务器运行良好,但有时会发生错误,为人们提供错误的页面 - 其他人请求的页面!

This error has been driving me nuts. We have a server running Apache and Tomcat, serving multiple different sites. Normally the server runs fine, but sometimes an error happens where people are served the wrong page - the page that somebody else requested!

线索:

  • 正在传送的页面是其他用户最近请求的页面,否则会正确传送.众所周知,要交换两个同时的请求.据我所知,所有被错误传送的页面都不会超过几分钟.
  • 它只影响由 Tomcat 提供服务的文件.图片等静态文件不受影响.
  • 它不会一直发生.当它发生时,它会发生在每个人身上.
  • 这似乎发生在需求高峰期.但是,需求还不是很高 - 这当然在 Apache 可以应付的范围内.
  • 重新启动 Tomcat 修复了它,但只修复了几分钟.重新启动 Apache 修复了它,但只修复了几分钟.
  • 服务器运行 Apache 2 和 Tomcat 6,在 Gentoo 上使用 Java 6 虚拟机.连接是与 AJP13 的,并且 块中的 JkMount 指令是正确的.
  • 在任何日志文件中都没有任何用处.
  • The pages being delivered are those that another user requested recently, and are otherwise delivered correctly. It's been known for two simultaneous requests to be swapped. As far as I can tell, none of the pages being incorrectly delivered are older than a few minutes.
  • It only affects the files that are being served by Tomcat. Static files like images are unaffected.
  • It doesn't happen all the time. When it does happen, it happens for everybody.
  • It seems to happen at times of peak demand. However, the demand is not yet very high - it's certainly well within the bounds of what Apache can cope with.
  • Restarting Tomcat fixed it, but only for a few minutes. Restarting Apache fixed it, but only for a few minutes.
  • The server is running Apache 2 and Tomcat 6, using a Java 6 VM on Gentoo. The connection is with AJP13, and JkMount directives within <VirtualHost> blocks are correct.
  • There's nothing of use in any of the log files.

更多信息:

Apache 没有开启任何形式的缓存.httpd.conf 和相关导入中所有与缓存相关的条目说,例如:

Apache does not have any form of caching turned on. All the caching-related entries in httpd.conf and related imports say, for example:

<IfDefine CACHE>
  LoadModule cache_module modules/mod_cache.so
</IfDefine>

虽然 Apache 的选项不包含该标志:

While the options for Apache don't include that flag:

APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D SSL -D SSL_DEFAULT_VHOST -D PHP5 -D JK"

Tomcat 同样没有打开缓存选项,我可以找到.

Tomcat likewise has no caching options switched on, that I can find.

工具包的建议很好,但在这种情况下不合适.是什么让我相信错误不能在我自己的代码中是因为它不仅仅是正在传输的几个值 - 它是整个请求,包括 URL、参数、会话 cookie 等等.人们正在返回页面说您以 John 的身份登录",而他们显然不是.

toolkit's suggestion was good, but not appropriate in this case. What leads me to believe that the error can't be within my own code is that it isn't simply a few values that are being transferred - it's the entire request, including the URL, parameters, session cookies, the whole thing. People are getting pages back saying "You are logged in as John", when they clearly aren't.

更新:

根据几个人的建议,我将以下 HTTP 标头添加到 Tomcat 服务的页面以禁用所有形式的缓存:

Based on suggestions from several people, I'm going to add the following HTTP headers to Tomcat-served pages to disable all forms of caching:

Cache-Control: no-store
Vary: *

希望这些标头不仅能被 Apache 尊重,还能被任何其他可能妨碍的缓存或代理尊重.不幸的是,我无法故意重现这个错误,所以我只能等待,看看它是否会再次出现.

Hopefully these headers will be respected not just by Apache, but also by any other caches or proxies that may be in the way. Unfortunately I have no way of deliberately reproducing this error, so I'm just going to have to wait and see if it turns up again.

我注意到包含以下标题 - 它们是否有任何关联?

I notice that the following headers are being included - could they be related in any way?

Connection: Keep-Alive
Keep-Alive: timeout=5, max=66

<小时>

更新:

显然这种情况在我睡着时又发生了,但现在我醒了才看到它已经停止发生了.同样,我可以看到日志中没有任何有用的东西,所以我不知道实际发生了什么或如何防止它发生.

Apparently this happened again while I was asleep, but has stopped happening now I'm awake to see it. Again, there's nothing useful in the logs that I can see, so I have no clues to what was actually happening or how to prevent it.

是否可以在 Apache 或 Tomcat 的日志中添加任何额外信息以使其更易于诊断?

Is there any extra information I can put in Apache or Tomcat's logs to make this easier to diagnose?

更新:

由于这种情况再次发生了几次,我们已经更改了 Apache 连接到 Tomcat 的方式,以查看它是否会影响某些事情.我们使用 mod_jk 和这样的指令:

Since this has happened again a couple of times, we've changed how Apache connects to Tomcat to see if it affects things. We were using mod_jk with a directive like this:

JkMount /portal ajp13

我们现在切换到使用 mod_proxy_ajp,如下所示:

We've switched now to using mod_proxy_ajp, like so:

ProxyPass /portal ajp://localhost:8009/portal

我们会看看它是否有什么不同.这个错误总是令人讨厌地不可预测,所以我们永远无法确定它是否有效.

We'll see if it makes any difference. This error was always annoyingly unpredictable, so we can never definitively say if it's worked or not.

更新:

我们只是在一个使用 mod_jk 留下的站点上短暂地得到了错误,而在同一台服务器上使用 mod_proxy_ajp 的姊妹站点没有显示错误.这并不能证明什么,但它确实提供了证据表明切换到 mod_proxy_ajp 可能有所帮助.

We just got the error briefly on a site that was left using mod_jk, while a sister site on the same server using mod_proxy_ajp didn't show the error. This doesn't prove anything, but it does provide evidence that swithing to mod_proxy_ajp may have helped.

更新:

昨晚我们刚刚在一个使用 mod_proxy_ajp 的网站上再次遇到错误,很明显这并没有解决 - mod_jk 不是问题的根源.我将尝试关闭持久连接的匿名建议:

We just got the error again last night on a site using mod_proxy_ajp, so clearly that hasn't solved it - mod_jk wasn't the source of the problem. I'm going to try the anonymous suggestion of turning off persistent connections:

KeepAlive Off

如果这也失败了,我会非常绝望地开始研究 GlassFish.

If that fails as well, I'm going to be desperate enough to start investigating GlassFish.

更新:

该死!问题刚刚回来.我有一段时间没看到它了,所以我开始认为我们终于把它整理好了.我讨厌黑森虫.

Dammit! The problem just came back. I hadn't seen it in a while, so I was starting to think we'd finally sorted it. I hate heisenbugs.

推荐答案

我们将 Apache 从使用 AJP 代理切换为使用 HTTP 代理.到目前为止,它似乎已经解决了这个问题,或者至少大大减少了它——这个问题已经好几个月没有报告了,而且自那以后该应用的使用量有所增加.

We switched Apache from proxying with AJP to proxying with HTTP. So far it appears to have solved the issue, or at least vastly reduced it - the problem hasn't been reported in months, and the app's use has increased since then.

更改在 Apache 的 httpd.conf 中.从 mod_jk 开始:

The change is in Apache's httpd.conf. Having started with mod_jk:

JkMount /portal ajp13

我们切换到mod_proxy_ajp:

ProxyPass /portal ajp://localhost:8009/portal

最后直接mod_proxy:

ProxyPass /portal http://localhost:8080/portal

您需要确保将 Tomcat 设置为在端口 8080 上提供 HTTP 服务.请记住,如果您正在提供 / 服务,则需要包含 /在代理的两侧或它开始哭泣:

You'll need to make sure Tomcat is set up to serve HTTP on port 8080. And remember that if you're serving /, you need to include / on both sides of the proxy or it starts crying:

ProxyPass / http://localhost:8080/

这篇关于Apache/Tomcat 错误 - 正在传送错误的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆