快速体验
快速体验 FGW
从 GitHub 克隆 FGW 仓库。
git clone https://github.com/flomesh-io/fgw.git
进入到工程的根目录,运行 pipy
并指定入口文件 ./pjs/main.js
。
cd fgw
pipy ./pjs/main.js
使用工程中默认的配置(./pjs/config.json
)启动,将监听 3 个端口:
8080
:代理的端口,将请求负载均衡到另外两个静态服务8081
:从/var/www/html
目录启动的静态服务8082
:从static/www2
目录启动的静态服务
本地
/var/www/html
目录不存在,因此当访问8081
的服务时,会报404
的错误。
curl -I localhost:8081
HTTP/1.1 404 Not Found
content-length: 0
connection: keep-alive
curl -I localhost:8082
HTTP/1.1 200 OK
content-type: text/html
content-length: 72
connection: keep-alive
当我们访问代理的 8080
端口时,即使上游的两个静态服务权重都是 50
,响应都是 200
。
curl -I localhost:8080
HTTP/1.1 200 OK
content-type: text/html
content-length: 72
set-cookie: _srv_id=3021372512864600; path=/; expires=Fri, 4 Aug 2023 02:23:59 GMT; max-age=3600
connection: keep-alive
这是因为配置了健康检查,FGW 会主动对上游进行健康检查,响应状态码为 200
的上游才被认为是健康的,否则将其从负载均衡列表中移除。
{
"Services": {
"backendService1": {
"HealthCheck": {
"Interval": 10,
"MaxFails": 3,
"FailTimeout": 30,
"Uri": "/",
"Matches": [
{
"Type": "status",
"Value": "200"
}
]
}
}
}
}
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
最后修改 November 29, 2023: add docs for fault injection and request mirror, fix typo (b53e400)