当前位置: 首页 > news >正文

nginx日志的一点理解

1、access.log什么时候打印?

经过测试,观察到access.log是在后端返回响应结果之后才打印的,不过也很好理解,nginx要等后端返回才知道是否处理成功。

2、nginx什么时候出现upstream timed out?

nginx超时时间<接口响应时间,就会出现upstream timed out.

3、nginx什么时候出现no live upstreams?

测试过程日下

后端接口:

@RestController
public class BasicController {private static final Logger logger = LoggerFactory.getLogger(BasicController.class);@GetMapping("/xxx/test")public String hello() throws InterruptedException {logger.info("xxxtest");Thread.sleep(50000);return "success";}
}

开启了两个端口8080和8081,启动项目

nginx配置如下:


worker_processes  1;events {worker_connections  1024;
}http {include       mime.types;default_type  application/json;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;# 指定前端项目所在的位置error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location / {  # 设置超时时间  proxy_read_timeout 20s;  proxy_connect_timeout 20s;  proxy_send_timeout 20s;proxy_next_upstream error timeout;# 其他代理设置(可选)proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;proxy_pass http://backend;}}upstream backend {server 127.0.0.1:8080;server 127.0.0.1:8081;}
}

日志如下:

access.log

127.0.0.1 - - [07/Jun/2025:22:53:32 +0800] "GET /xxx/test HTTP/1.1" 502 497 "-" "PostmanRuntime/7.44.0"
127.0.0.1 - - [07/Jun/2025:22:53:50 +0800] "GET /xxx/test HTTP/1.1" 504 497 "-" "PostmanRuntime/7.44.0"

error.log

2025/06/07 22:53:30 [error] 44212#13196: *25 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /xxx/test HTTP/1.1", upstream: "http://127.0.0.1:8081/xxx/test", host: "localhost"
2025/06/07 22:53:32 [error] 44212#13196: *27 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /xxx/test HTTP/1.1", upstream: "http://127.0.0.1:8080/xxx/test", host: "localhost"
2025/06/07 22:53:32 [error] 44212#13196: *27 no live upstreams while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /xxx/test HTTP/1.1", upstream: "http://backend/xxx/test", host: "localhost"
2025/06/07 22:53:50 [error] 44212#13196: *25 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /xxx/test HTTP/1.1", upstream: "http://127.0.0.1:8080/xxx/test", host: "localhost"


 

 

http://www.lqws.cn/news/213607.html

相关文章:

  • Xxl-job——源码设计思考
  • Kerberos面试内容整理-未来发展趋势
  • 【大模型】大模型RAG(Retrieval-Augmented Generation)面试题合集
  • 解密LSTM(长短期记忆网络):让机器拥有记忆力的魔法网络
  • 【PhysUnits】15.17 比例因子模块 (ratio.rs)
  • 第二部分 方法,还是方法——“信管法则”的四大要点
  • 号外!PLC和安川伺服,通过Profinet转EtherCAT网关同步多个工作站的运动
  • SpiritTools:一款小而精的实用工具箱
  • 20250607在荣品的PRO-RK3566开发板的Android13系统下实现长按开机之后出现插入适配器不会自动启动的问题的解决
  • 20250607在荣品的PRO-RK3566开发板的Android13的uboot中使用gpio命令来配置GPIO的状态
  • 【Hugging Face】实践笔记:Pipeline任务、BERT嵌入层、Train任务、WandB解析
  • Python 训练营打卡 Day 38-Dataset和Dataloader类
  • Pytorch学习——自动求导与计算图
  • Spring AI与Spring Modulith核心技术解析
  • 如何判断指针是否需要释放?
  • [面试精选] 0104. 二叉树的最大深度
  • 初识redis
  • Kafka 消息模式实战:从简单队列到流处理(一)
  • c++ 静态成员变量
  • 《高精度》题集
  • 【题解-洛谷】B3622 枚举子集(递归实现指数型枚举)
  • 【Latex】Windows/Ubuntu 绘制 eps 矢量图通用方法(drawio),支持插入 Latex 数学公式
  • 一款“短小精悍的”手机录屏软件
  • 安达发|装饰材料行业APS生产排程软件:破解生产困局,智造升级新引擎
  • Java高级 |【实验八】springboot 使用Websocket
  • Spring中循环依赖问题的解决机制总结
  • day 27 装饰器函数
  • [GitHub] 优秀开源项目
  • 区块链技术概述
  • Java方法引用深度解析:从匿名内部类到函数式编程的演进