【问题标题】:how to expose functionality from reverseproxy service如何从反向代理服务公开功能
【发布时间】:2018-09-05 02:26:07
【问题描述】:

我有一个反向代理服务,我正在使用SharpReverseProxy 来处理所有传入的请求:

为了配置服务,下面的代码在Startup类中:

public void Configure(IApplicationBuilder app, 
    IHostingEnvironment env, 
    ILoggerFactory loggerFactory) {

    app.UseProxy(new List<ProxyRule> {
        new ProxyRule {
            Matcher = uri => uri.AbsoluteUri.Contains("/api/"),
            Modifier = (req, user) => {
                var match = Regex.Match(req.RequestUri.AbsolutePath, "/api/(.+)service");
                req.RequestUri = new Uri(string.Format("http://{0}.{1}/{2}",
                    match.Groups[1].Value,
                    req.RequestUri.Host,
                    req.RequestUri.AbsolutePath.Replace(match.Value, "/api/")
                ));
            },
            RequiresAuthentication = true
        }
    },
    r => {
        _logger.LogDebug($"Proxy: {r.ProxyStatus} Url: {r.OriginalUri} Time: {r.Elapsed}");
        if (r.ProxyStatus == ProxyStatus.Proxied) {
            _logger.LogDebug($"        New Url: {r.ProxiedUri.AbsoluteUri} Status: {r.HttpStatusCode}");
        }
    });
}

如何公开此服务,以便我可以从外部 https 访问它?

我知道我们可以像这样使用FabricTransportServiceRemotingListener 添加一个监听器:

                        new ServiceInstanceListener(serviceContext => new FabricTransportServiceRemotingListener(serviceContext,
                new MyService(),
                new FabricTransportRemotingListenerSettings
                {
                    EndpointResourceName = "MyServiceEndpoint"
                }), "MyServiceEndpoint"),

我的问题是,我不明白应该用 MyService() 替换什么,因为顶部的 ReverseProxy 代码没有服务。

如何将反向代理配置公开为服务,从而能够通过FabricTransportRemotingListenerSettings 公开它?

【问题讨论】:

    标签: c# .net visual-studio-2017 azure-service-fabric


    【解决方案1】:

    你不能。 SF remoting 是一种特定于平台的通信机制。此外,它不打算在集群外部使用。

    您可以公开HttpSysCommunicationListener 以将您的代理公开为可靠服务的HTTP endpoint

    确保按照说明将端点配置为 HTTPS。

    【讨论】:

      猜你喜欢
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 2010-10-27
      • 2012-04-26
      • 1970-01-01
      相关资源
      最近更新 更多