簡體   English   中英

Yarp 代理不記錄重定向?

[英]Yarp proxy does not log a redirect?

我目前正在玩 YARP(又一個反向代理)並且似乎已經設法“縮短”重定向?

其中一個重定向正在被記錄,而另一個沒有被記錄,盡管它們的設置方式相同?

程序.cs

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));

var app = builder.Build();

app.MapReverseProxy();

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

appsetting.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ReverseProxy": {
    "Routes": {
      "serverforce": {
        "ClusterId": "serverforce",
        "Match": {
          "Path": "google"
        }
      },
      "azure": {
        "ClusterId": "azure",
        "Match": {
          "Path": "msn"
        }
      }
    },
    "Clusters": {
      "serverforce": {
        "Destinations": {
          "google": {
            "Address": "https://google.de/"
          }
        }
      },
      "azure": {
        "Destinations": {
          "msn": {
            "Address": "https://www.msn.com/da-dk"
          }
        }
      }
    }
  }
}

https://localhost:7147/msn 使用日志消息將我重定向到https://www.msn.com/da-dk

info: Yarp.ReverseProxy.Forwarder.HttpForwarder[9]
      Proxying to https://www.msn.com/da-dk/msn HTTP/2 RequestVersionOrLower no-streaming

https://localhost:7147/google 將我重定向到https://www.google.dk ,沒有日志消息

為什么 O 沒有收到任何日志消息? 為什么是舊站點,而不是最新站點? 我嘗試多次重建和清理重建項目?

回答你的問題。 我已經測試了您的配置,一切都被正確記錄。 這是我的項目文件

 <Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Yarp.ReverseProxy" Version="1.0.0" />
  </ItemGroup>

</Project>

日志:

在此處輸入圖像描述

嘗試刪除 bin 和 obj 文件夾


使用反向代理進行重定向是不正確的。 反向代理用於隱藏原始服務器的存在和特征( https://en.wikipedia.org/wiki/Reverse_proxy

您看到的是原始服務器將您重定向到另一個 URL。例如,您請求https://www.msn.com/da-dk/msn ,而 msn 正在重定向到https://www.msn。 com/da-dk?r=1

試試這個例子,觀察會發生什么:

  "ReverseProxy": {
    "Routes": {
      "bbc": {
        "ClusterId": "bbc",
        "Match": {
          "Path": "news"
        }
      }
    },
    "Clusters": {
      "bbc": {
        "Destinations": {
          "msn": {
            "Address": "https://www.bbc.com/"
          }
        }
      }
    }
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM