记录nginx 502

1.开启日志记录分析

http
{
        #定义日志格式
        log_format  main
          ' $remote_user [$time_local] $status $http_x_Forwarded_for $remote_addr $request '
         '$http_x_forwarded_for '
         '$upstream_addr '
         'ups_resp_time: $upstream_response_time '
         'request_time: $request_time';

        #access_log off;
        access_log /usr/local/nginx/logs/access.log ;
        #error_log /dev/null;
        error_log  /usr/local/nginx/logs/error.log debug;

        # ---------------均衡负载----------------
        upstream ADMIN
        {
                server 192.168.11.11:8090 weight=1 max_fails=2 fail_timeout=30s;
                server 192.168.11.22:8090 weight=1 max_fails=2 fail_timeout=30s;
        }
server
{
    listen 80;
        listen 443 ssl;
    server_name xxx.com;

    #SSL开始,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;

    include 301ssl.conf;

        #SSL配置开始
    ssl_certificate   /usr/local/nginx/conf/ssl/xxx/Nginx/xxx-certificate-with-chain.pem;
    ssl_certificate_key    /usr/local/nginx/conf/ssl/xxx/Nginx/xxx-PrivateKEY.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    error_page 497  https://$host$request_uri;
        #SSL配置结束
        #include config.conf;

        location /
        {
        proxy_pass http://ADMIN;
        proxy_buffer_size 64k;
        proxy_buffers   32 32k;
        proxy_busy_buffers_size 128k;
        proxy_connect_timeout      70;
        proxy_read_timeout         70;
        proxy_send_timeout         70;
        proxy_next_upstream http_502 http_504 error timeout invalid_header;
        proxy_set_header Host $host;
        proxy_set_header X-Real_IP $remote_addr;
        proxy_set_header X-Forwarded-for $remote_addr;
        access_log     /usr/local/nginx/logs/admin.log main;
        }
}

2.查看access日志分析

 - [14/Jun/2019:11:01:48 +0800] 504 - 192.168.11.1  GET /a/xxx HTTP/1.1 - 192.168.11.11:8090, 192.168.11.22:8090 ups_resp_time: 60.070, 60.069 request_time: 120.139		#服务请求再次请求两台后端超时重试1次 
 - [14/Jun/2019:11:01:48 +0800] 200 - 192.168.11.1  GET /a/xxx HTTP/1.1 - 192.168.11.11:8090 ups_resp_time: 0.527 request_time: 0.527
 - [14/Jun/2019:11:01:48 +0800] 499 - 192.168.11.1  GET /a/xxx HTTP/1.1 - 192.168.11.22:8090 ups_resp_time: - request_time: 60.069		#nginx请求超时 proxy_connect_timeout 60; 时间为60秒 数据库超时时间也是60s  提示499(客户端放弃请求)并将后端服务器192.168.11.22:8090 down停止请求
 - [14/Jun/2019:11:02:09 +0800] 504 - 192.168.11.1  POST /a/xxx HTTP/1.1 - 192.168.11.11:8090 ups_resp_time: 60.069 request_time: 60.069	#此时nginx显示超时504 timeout 并将后端服务器192.168.11.11:8090 down停止请求
 - [14/Jun/2019:11:02:09 +0800] 200 - 192.168.11.1  GET /a/xxx HTTP/1.1 - 192.168.11.11:8090 ups_resp_time: 0.770 request_time: 0.770
 - [14/Jun/2019:11:02:09 +0800] 502 - 192.168.11.1  GET /a/xxx HTTP/1.1 - ADMIN ups_resp_time: 0.000 request_time: 0.000		#两台后端服务器均被down	请求返回为空 
 - [14/Jun/2019:11:02:09 +0800] 502 - 192.168.11.1  GET /a/xxx HTTP/1.1 - ADMIN ups_resp_time: 0.000 request_time: 0.000
 - [14/Jun/2019:11:02:09 +0800] 502 - 192.168.11.1  GET /a/xxx HTTP/1.1 - ADMIN ups_resp_time: 0.000 request_time: 0.000
 - [14/Jun/2019:11:03:34 +0800] 200 - 192.168.11.1  GET /a/xxx HTTP/1.1 - 192.168.11.22:8090 ups_resp_time: 0.366 request_time: 0.366	#当proxy_connect_timeout 60  + fail_timeout 30  =90s 之后请求正常
 - [14/Jun/2019:11:03:35 +0800] 304 - 192.168.11.1  GET /css/style.css HTTP/1.1 - 192.168.11.22:8090 ups_resp_time: 0.166 request_time: 0.166
 - [14/Jun/2019:11:03:35 +0800] 304 - 192.168.11.1  GET /css/font-awesome.css HTTP/1.1 - 192.168.11.22:8090 ups_resp_time: 0.167 request_time: 0.167

3.调整timeout时间大于数据库连接超时时间

        proxy_connect_timeout      70;
        proxy_read_timeout         70;
        proxy_send_timeout         70;

4.查看日志

 - [14/Jun/2019:14:51:08 +0800] 200 - 192.168.11.1 GET /a/xxx  HTTP/1.1 - 192.168.11.11:8090 ups_resp_time: 60.147 request_time: 60.147

#服务请求超时  但是返回的状态是200  nginx正常运行

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值