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)
栏 目:Nginx
下一篇:Nginx反向代理后获取不到客户端的真实ip地址的解决方法
本文标题:nginx错误502,503,504分析
本文地址:https://www.zyku.net/nginx/1753.html
您可能感兴趣的文章
- 03-16详解centos7配置本地yum源的方法
- 02-23DedeCMS提示:Errorcheck Snooping out
- 09-18华为手机测量身高步骤分享
- 01-19个性签名网名分组-个性签名网名分组应
- 12-17魅族16sPro在哪关闭盲人模式
- 01-19facer表盘-facer表盘应用软件功能介绍
- 12-25苹果xrNFC功能怎么开启
- 09-29华为nova9安全锁在哪里开
- 01-11科学钢琴-科学钢琴应用软件功能介绍
- 08-13微信视频号如何开小游戏直播?
- 03-04wordpress防止垃圾评论的几种方法
- 01-12二胡校音器软件-二胡校音器软件应用软
- 03-22vivox60黑名单设置步骤教程
- 01-18王者荣耀特殊符号大全-王者荣耀特殊符
- 03-17详解Linux 中五个重启命令
- 06-21帝国CMS自动获取TAG首字母教程
- 01-11记录时间天数-记录时间天数应用软件功
- 01-17集分社-集分社应用软件功能介绍
- 01-10云上巴东-云上巴东应用软件功能介绍
- 01-11图片转文字识别王-图片转文字识别王应
最近更新
阅读排行
猜你喜欢
- 06-23帝国CMS增加信息时自动把内容图片的al
- 07-05Linux zip命令
- 10-26讯飞输入法怎样开启朗读
- 09-15Linux中ls命令只显示文件或者文件夹列
- 12-13HTML <time> 标签
- 03-11nginx+php-fpm组合解决PATHINFO最佳配
- 01-11红米k30电池健康值在哪看
- 09-17华为p40设置地震预警步骤介绍
- 03-04wordpress如何去除顶部的工具条(admin
- 04-05SQL Server 2005详细安装过程及配置