大网数据广告活动
服务器运维问答

What is causing this error on nginx server – 502 Bad gateway

· 52CE 我爱测

I have a site built in Drupal 7 on a nginx server. A few times a week when I edit any content and press save, or when I log in to the site, or when I change some configuration, I get a white screen with the message "502 Bad gatew…

问题原文

原帖链接 · TBJ · CC BY-SA 3.0

I have a site built in Drupal 7 on a nginx server. A few times a week when I edit any content and press save, or when I log in to the site, or when I change some configuration, I get a white screen with the message "502 Bad gateway". The error is never showed to anonymous visitors, only when logged in and saving changes. It doesn't seem to matter what kind of changes I do. I can press the back button in the browser, which takes me back to the edit screen and press save again, and save the change successfully.

The error happened again this morning at 08:09, so I looked at the PHP log:

2016/10/20 08:09:00 [error] 20703#20703: *3297348 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 195.198.76.66, server: www.example.com, request: "POST /node/88/edit HTTP/1.1", upstream: "fastcgi://unix:/run/php/php-fpm.sock:", host: "www.example.com", referrer: "http://www.example.com/node/88/edit"

And here is the nginx log at that same time:

[20-Oct-2016 08:09:00] WARNING: [pool www0] child 10909, script '/srv/www/example/public_html/index.php' (request: "POST /index.php") execution timed out (8189.954999 sec), terminating
[20-Oct-2016 08:09:00] WARNING: [pool www0] child 10909 exited on signal 15 (SIGTERM) after 19080.476683 seconds from start
[20-Oct-2016 08:09:00] NOTICE: [pool www0] child 13002 started

Can anyone see what is happening here?

社区高分解答

原帖链接 · antoineMoPa · CC BY-SA 4.0

I had a HTTP 502 problem on a setup with nginx & php-fpm. It seems that many timeouts & limits must be modified according to the data transfer time. What was happening in this case is that the keepalive timeout was too short.

Here are some settings that might help solve 502 problems:

  • In nginx.conf: keepalive_timeout
  • In the site's configuration file (which is in thesites-available folder):
    • send_timeout
    • fastcgi_connect_timeout
    • fastcgi_send_timeout
    • fastcgi_read_timeout
  • in php.ini:
    • max_execution_time
    • max_input_time

The real source of the problem can be any of these settings.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。