Linux查找文件内指定内容(排查nginx配置文件中的超时配置)

背景说明

本文记录了通过egrep命令查找文件内是否包含指定内容指定字段,进一步定位nginx配置文件中是否存在异常配置项。
开发在测试接口时,发现大部分接口正常,其中有一个接口异常并报错timeout。反过来让我检查nginx是否配置了连接超时配置。ok,nginx服务器是我装的,但配置文件是前端自己修改过的。怎么都沾边,那就查呗。

  • 接口超时截图如下
    在这里插入图片描述

参考文章

【常见的nginx超时配置】
【Linux egrep命令|菜鸟教程】

nginx常见超时配置项

Nginx 中的超时设置包括:

“client_body_timeout”:设置客户端向服务器发送请求体的超时时间,单位为秒。

“client_header_timeout”:设置客户端向服务器发送请求头的超时时间,单位为秒。

“send_timeout”:设置服务器向客户端发送响应的超时时间,单位为秒。

“keepalive_timeout”:设置服务器与客户端之间保持连接的超时时间,单位为秒。

“proxy_connect_timeout”:设置代理服务器与后端服务器建立连接的超时时间,单位为秒。

“proxy_read_timeout”:设置代理服务器从后端服务器读取数据的超时时间,单位为秒。

“proxy_send_timeout”:设置代理服务器向后端服务器发送数据的超时时间,单位为秒。

Linux egrep命令使用

  • Linux egrep命令用于在文件内查找指定的字符串。

egrep执行效果与"grep-E"相似,使用的语法及参数可参照grep指令,与grep的不同点在于解读字符串的方法。

egrep是用extended regular expression语法来解读的,而grep则用basic regular expression 语法解读,extended regular expression比basic regular expression的表达更规范。

  • 语法
egrep [范本模式] [文件或目录] 
  • 参数说明:
[范本模式] :查找的字符串规则。
[文件或目录] :查找的目标文件或目录。
  • 实例
    显示文件中符合条件的字符。例如,查找当前目录下所有文件中包含字符串"Linux"的文件,可以使用如下命令:
egrep Linux *

结果如下所示:

$ egrep Linux * #查找当前目录下包含字符串“Linux”的文件  
testfile:hello Linux! #以下五行为testfile 中包含Linux字符的行  
testfile:Linux is a free Unix-type operating system.  
testfile:This is a Linux testfile!  
testfile:Linux  
testfile:Linux  
testfile1:helLinux! #以下两行为testfile1中含Linux字符的行  
testfile1:This a Linux testfile!  
#以下两行为testfile_2 中包含Linux字符的行  
testfile_2:Linux is a free unix-type opterating system.  
testfile_2:Linux test  
xx00:hello Linux! #xx00包含Linux字符的行  
xx01:Linux is a free Unix-type operating system. #以下三行为xx01包含Linux字符的行  
xx01:This is a Linux testfile!  
xx01:Linux 

排查问题

测试环境nginx配置文件结构

在这里插入图片描述

通过egrep命令查询文件中指定内容

[sysma@nginx-0001 nginx]$ pwd
/usr/local/nginx
[sysma@nginx-0001 nginx]$ egrep 4502 -r conf/vhost/*
conf/vhost/mxxxxxxxt.conf:    listen 4502;
[sysma@nginx-0001 nginx]$ 
[sysma@nginx-0001 nginx]$ egrep timeout -r conf/vhost/mxxxxxxxt.conf 
    #ssl_session_timeout  5m;    #缓存有效期
    #     proxy_read_timeout 3600s; 
[sysma@nginx-0001 nginx]$ 
[sysma@nginx-0001 nginx]$ egrep timeout -r conf/*
conf/nginx.conf:    #keepalive_timeout  0;
conf/nginx.conf:    #keepalive_timeout  0
conf/nginx.conf.default:    #keepalive_timeout  0;
conf/nginx.conf.default:    keepalive_timeout  65;
conf/nginx.conf.default:    #    ssl_session_timeout  5m;
conf/vhost/mxxxxxxt.conf:    #ssl_session_timeout  5m;    #缓存有效期
conf/vhost/mxxxxxxt.conf:    #     proxy_read_timeout 3600s; 
conf/vhost/nxxxxxa.conf:    ssl_session_timeout  5m;    #缓存有效期
conf/vhost/cxxxxxxxxxxxxxs.conf:  # ssl_session_timeout 5m; #缓存有效期
[sysma@nginx-0001 nginx]$ 

排除nginx是故障原因,成功甩锅

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值