nginx php 503,nginx错误502,503,504分析

开发过程中我们经常会遇到nginx 502,503,504错误,这些错误代表什么?什么情况下会出现这些错?下面一一说明(均以nignx+php-fpm举例):

wikipedia上这么解释:

502 Bad Gateway

The server was acting as a gateway or proxy and received an invalid response from the upstream server.

503 Service Unavailable

The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.

504 Gateway Time-out

The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.

502 Bad Gateway

fpm进程挂掉或者后端程序过长时间未返回。

编写一个简单的php脚本gateway.php进行测试,内容很简单 <?php sleep(10);echo ‘ok;’?> ,开始下面的测试:

1.启动nginx,不启动fpm,直接 curl http://localhost/gateway.php ,响应502 bad gateway错误且nginx的error log出现错误

2017/02/10 19:08:21 [error] 216#216: *84 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: website80.com, request: "GET /gateway.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

2.启动fpm,修改php-fpm.conf中request_terminate_timeout的值为5s。继续 curl http://localhost/gateway.php ,响应502 bad gateway。nginx和php-fpm分别报错

// nginx error log

2017/02/10 19:10:57 [error] 246#246: *88 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.17.0.1, server: website80.com, request: "GET /gateway.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

// php-fpm error log

[10-Feb-2017 19:10:57] WARNING: [pool www] child 242, script '/home/website/default/gateway.php' (request: "GET /gateway.php") execution timed out (6.205572 sec), terminating

[10-Feb-2017 19:10:57] WARNING: [pool www] child 242 exited on signal 15 (SIGTERM) after 36.692467 seconds from start

503 Service Unavailable

当遇到这个状态码的时候表示服务临时不可用,比如nginx配置了频率限制而client端又超过了配置的限制后就会收到503的响应。

504 Gateway Time-out

nginx的fastcgi模块有一个fastcgi_read_timeout配置,它表示从FastCGI server获取数据的超时时间。如果超过这个配置客户端就是收到504的响应。还以 gateway.php 举例(修改fastcgi_read_timeout的值为5s):

// nginx error log

2017/02/12 14:57:26 [error] 138#138: *1113 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 172.17.0.1, server: website80.com, request: "GET /gateway.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

(资源库 www.zyku.net)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值