1

This Windows service and has some web api controllers. The IIS which we want to use as reverse proxy already has some services hosted on it.

Below is the Program class for windows service. Is it possible to use IIS as reverse proxy where IIS takes request and pass on to windows service which is running on kestrel server.

Any help is appreciated. Thanks.

public class Program
    {
        private static async Task Main(string[] args)
        {
            var isService = !(Debugger.IsAttached || args.Contains("--console"));

            var builder = CreateWebHostBuilder(args.Where(arg => arg != "--console").ToArray());

            var host = builder.Build();

            if (isService)
            {
                host.RunAsService();
            }
            else
            {
                host.Run();
            }
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseKestrel((context, serverOptions) =>
                {
                    serverOptions.Configure(context.Configuration.GetSection("Kestrel"))
                        .Endpoint("HTTPS", listenOptions =>
                        {
                            listenOptions.HttpsOptions.SslProtocols = SslProtocols.Tls12;
                        });
                })
                .UseIISIntegration()
                .UseUrls("https://MyMachineName");
    }

BElow is kestrel configuration is appsettings.json

"Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:6000"
      },
      "Https": {
        "Url": "https://*:6001"
      }
    },
    "Certificates": {
      "Default": {
        "Subject": "certificatename",
        "Store": "Root",
        "Location": "LocalMachine",
        "AllowInvalid": true
      }
    }
  }
manojmore
  • 410
  • 2
  • 8
  • 20
  • Why not just host the service in the IIS itself and make it always running with the help of [Application Initialization](https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-application-initialization). – Angel Yordanov Jul 02 '20 at 09:57
  • This article explains in detail how to host an ASP .NET Core app with IIS as a reverse proxy for kestrel: [Host ASP.NET Core on Windows with IIS](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.1&tabs=aspnetcore2x) – Jalpa Panchal Jul 03 '20 at 05:48
  • I'm interested in why you would choose IIS as the reverse-proxy of your application, instead of something like nginx or traefik – Malte R Jul 09 '20 at 09:10

0 Answers0