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

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.xdnf.cn/news/12630.html

相关文章:

  • Nginx 事件驱动理解
  • LeetCode 118 杨辉三角 (Java)
  • 移动应用开发专业核心课程以及就业方向
  • QT使用AES加解密,openssl及QCA问题记录
  • OpenLayers 从后端服务加载 GeoJSON 数据
  • Windows 下搭建 Zephyr 开发环境
  • Linux 文件系统与 I/O 编程核心原理及实践笔记
  • 【科研绘图系列】R语言绘制论文组图(multiple plots)
  • BERT, GPT, Transformer之间的关系
  • 接口不是json的内容能用Jsonpath获取吗,如果不能,我们选用什么方法处理呢?
  • 巴西医疗巨头尤迈Kafka数据泄露事件的全过程分析与AI安防策略分析
  • wpf的converter
  • python学习打卡day47
  • 6.7本日总结
  • 微前端 - Native Federation使用完整示例
  • Spring Boot 3.3 + MyBatis 基础教程:从入门到实践
  • JAVA理论第五章-JVM
  • Oracle 审计参数:AUDIT_TRAIL 和 AUDIT_SYS_OPERATIONS
  • 仿真每日一练 | Workbench曲柄滑块机构刚体动力学分析
  • 跳转指令四维全解:从【call/jmp 】的时空法则到内存迷宫导航术
  • 数据库系统概论(十七)超详细讲解数据库规范化与五大范式(从函数依赖到多值依赖,再到五大范式,附带例题,表格,知识图谱对比带你一步步掌握)
  • 深入理解PHP安全漏洞:文件包含与SSRF攻击全解析
  • 在线汉字笔画练习工具(HTML文件版)
  • 【LLM-Agent】智能体的记忆缓存设计
  • 《DeepSeek R1-0528与ChatGPT o3对比分析》
  • 在边缘部署实时视觉应用程序
  • AdaFactor Optimizer 大模型训练优化器简介
  • 多线程2(Thread)
  • C++算法-动态规划2
  • 前端基础之《Vue(19)—状态管理》