yarp 取代Nginx的几个配置项:
路由匹配:
Nginx:
location /WebUI
Yarp:在Routes中增加
"svc-web-route": {
"ClusterId": "svc-web-cluster",
"Match": {
"Path": "/WebUI/{**catch-all}"
}
},
路由转发:
Nginx:
proxy_pass http://svc-api;
Yarp: 在Clusters中增加
"Destinations": {
"svc-api-destination": {
"Address": "http://svc-api"
}
},
默认页面:
Nginx:
index index.html index.htm;
Yarp:暂时没找到,可由程序完成默认路由
超时配置
Nginx:
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
Yarp:在Clusters中增加
"HttpRequest": {
"ActivityTimeout": "00:03:00"
}
重定向关闭
proxy_redirect off;
替换方案:默认关闭
Forward配置
Nignx:
proxy_set_header X-Forwarded-Proto $http_X_Forwarded_Proto;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Yarp:默认 X-Forwarded-For,X-Forwarded-Proto,X-Forwarded-Host ,可在 Transforms 中修改
地址重写
我们一般会增加一个固定前缀到后端,或者删除一个前缀到后端
nginx: rewrite
Yarp: route中增加
"Transforms": [
{ "PathRemovePrefix": "/OMS" }
]