[英]Yarp Reverse Proxy - Response 502 Bad Gateway
I want to implement a reverse proxy using Yarp.我想使用 Yarp 实现反向代理。 The Api is up and running as i can send request to it.
Api 已启动并正在运行,因为我可以向它发送请求。 However, anytime i try the same request through the proxy, i get an error 502 Bad gateway
但是,每当我通过代理尝试相同的请求时,我都会收到错误 502 Bad gateway
Startup.cs启动.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddReverseProxy()
.LoadFromConfig(Configuration.GetSection("ReverseProxy"));
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
// Register the reverse proxy routes
app.UseEndpoints(endpoints =>
{
endpoints.MapReverseProxy();
});
}
Appsettings应用设置
"ReverseProxy": {
"Routes": {
"route1": {
"ClusterId": "cluster1",
"Match": {
//"Methods": [ "GET", "POST", "PUT", "HEAD", "OPTIONS", "DELETE" ],
"Path": "{**catch-all}"
}
}
},
"Clusters": {
"cluster1": {
"Destinations": {
"cluster1/destination1": {
"Address": "https://localhost:44339/"
}
}
}
}
}
I am getting a response - 502 bad gateway anytime i send a request through the proxy我收到响应 - 502 bad gateway 每当我通过代理发送请求时
You should click output
and select ProjectName-Asp.Net Core Web Server
to check the details.您应该单击
output
并选择ProjectName-Asp.Net Core Web Server
以检查详细信息。
I use your code and also append another settings, and check the logs, I found the reason is http://localhost:44339 not start.我使用您的代码并附加了另一个设置,并检查了日志,我发现原因是 http://localhost:44339 无法启动。 It should use another webapp's port in local.
它应该在本地使用另一个 webapp 的端口。
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
//"AllowedHosts": "*"
"ReverseProxy": {
"Routes": [
{
"ClusterId": "cluster1",
"Match": {
//"Methods": [ "GET", "POST", "PUT", "HEAD", "OPTIONS", "DELETE" ],
"Path": "{**catch-all}"
}
},
{
// matches /something/* and routes to 2 external addresses
"ClusterId": "cluster2",
"Match": {
"Path": "/something/{*any}"
}
}
],
"Clusters": {
"cluster1": {
"Destinations": {
"cluster1/destination1": {
"Address": "http://localhost:44339/"
}
}
},
"cluster2": {
"Destinations": {
"first_destination": {
"Address": "https://baidu.com"
},
"another_destination": {
"Address": "https://bing.com"
}
},
"LoadBalancingPolicy": "PowerOfTwoChoices"
}
}
}
}
default: https://localhost:44370默认:https://localhost:44370
https://localhost:44370/somthing https://localhost:44370/somthing
it will redirect to bing site.它将重定向到 bing 站点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.