nginx容器转发请求超时(upstream timed out)
报错:
2022/08/10 02:11:01 [error] 30#30: *1 upstream timed out (110: >Connection timed out) while connecting to upstream, client: >192.168.137.78, server: localhost, request: "POST /api/login HTTP/1.1", >upstream: "http://192.168.137.78:8081/login", host: "192.168.137.78" 2022/08/10 02:11:01 [error] 30#30: *1 open() "/etc/nginx/html/50x.html" >failed (2: No such file or directory), client: 192.168.137.78, server: >localhost, request: "POST /api/login HTTP/1.1", upstream: >"http://192.168.137.78:8081/login", host: "192.168.137.78"
分析:
- 首先查看请求转发地址(http://192.168.137.78:8081/login),没有问题。说明配置文件种请求转发配置正常。
- 在nginx的容器与物理机中分别请求该地址(curl 192.168.137.78:8081/login )
- 两次分别请求发现,物理机上请求正常返回,nginx容器中请求无响应。分析,nginx容器无法请求到后端服务器。
结果
防火墙后端端口8081没有开放。
ubuntu系统:ufw allow 8081