7

所以我有一个疯狂的小时试图弄清楚为什么我的日志在过去的几个小时里每分钟都会出现几次缓慢的 php 脚本警告。

我最初专注于 php 慢日志和 php 错误日志,我吓坏了,以为这是我的代码。碰巧我正在实施一些 DNS 调整,这就是为什么我走错了路。

我最终检查了 nginx 错误日志,该日志显示了由几乎相同的 IP 对等方重置的一行又一行的连接。

我用谷歌搜索了这些 IP,发现它属于谷歌,所以这显然是一个谷歌机器人/蜘蛛访问该网站。

这是错误日志的剪辑

2013/06/06 14:04:05 [error] 12313#0: *7435269 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.187, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:04:05 [error] 12308#0: *7435135 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.167, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:04:05 [error] 12308#0: *7435994 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.199, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:04:12 [error] 12309#0: *7436209 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.168, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:05:12 [error] 12309#0: *7441608 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.177, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:05:15 [error] 12310#0: *7440634 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.219, server: www.domain.com, request: "GET /c.html?q= xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:05:15 [error] 12313#0: *7441634 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.194, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:06:02 [error] 12310#0: *7444721 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.221, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:06:05 [error] 12308#0: *7443911 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.203, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:06:05 [error] 12309#0: *7445423 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.164, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"
2013/06/06 14:06:05 [error] 12310#0: *7445640 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 209.85.238.222, server: www.domain.com, request: "GET /c.html?q=xyz HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.domain.com"

对等方重置连接的原因是什么。谷歌机器人真的会访问页面并终止请求,只是为了检查它是否还活着?

这不是很好,因为它调用了我的 curl 请求,然后由于客户端退出,这些请求属于孤立线程。这意味着他们只是超时导致缓慢的 php 脚本。

还是我读错了?

4

1 回答 1

0

如果您查看错误消息,它会说

从上游读取响应标头时

这意味着问题不在于 google 正在终止请求,而在于 nginx 的上游(恰好是 php-fpm)正在终止请求。通常,这是由正在运行的 php 代码错误引起的。

鉴于我们没有代码,以下是一些常规故障排除步骤:

  • 在 php-fpm 的配置中,增加request_terminate_timeout,max_input_time和的值max_execution_time
  • 在 php.ini 或 pool .conf 配置文件中激活错误日志记录(但不是“display_error”,如果它是一个生产网站)。
  • 尝试在正在运行的代码上运行调试器(xdebug 非常有用)来单步调试代码,你会偶然发现大多数问题。
于 2014-05-22T02:02:11.613 回答