Nginx排错:Nginx日志报错connect() failed (110: Connection timed out) while connecting to upstream
程序员文章站
2022-06-14 09:37:12
...
项目概述
网上商城项目,SpringCloud框架,Eureka端口10086,zuul端口10010,商品后端端口8001,前端端口9001
环境:
1、本地主机win10,ip:192.168.0.110,起后端和前端
2、虚拟机centos7,ip192.168.0.112,做反向代理服务器
3、修改本地主机host(C:\Windows\System32\drivers\etc\hosts)文件通过域名指向192.168.0.112
192.168.0.112 manage.leyou.com // 前端
192.168.0.112 api.leyou.com // zuul
192.168.0.112 www.leyou.com // 商城
4、nginx.conf文件添加以下内容
server {
listen 80;
server_name api.leyou.com;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://192.168.0.110:10010;
proxy_connect_timeout 6000;
proxy_read_timeout 6000;
}
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
问题描述
本机通过浏览器访问manage.leyou.com可以获得前端页面,当需要向后端发送请求获取数据时报错:
2020/04/29 17:48:11 [error] 22845#0: *118 connect() failed (110: Connection timed out) while connecting to upstream, client: 192.168.0.110, server: api.leyou.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://192.168.0.110:10010/favicon.ico", host: "api.leyou.com", referrer: "http://api.leyou.com/api/item/category/list?pid=0"
浏览器直接访问api.leyou.com出现nginx的502页面
问题解决
关闭虚拟机防火墙,关闭本机防火墙。