KestrelHttpServer icon indicating copy to clipboard operation
KestrelHttpServer copied to clipboard

Production Ready: Recommendation for Kestrel and Linux

Open kscott5 opened this issue 10 years ago • 33 comments

What is the recommended way to host a web application on Linux (Centos) using RC1?

I'm figure with iptables command but port 80 never appears to work. I can use a non-standard port such as 5000 just fine.

I've used ngix on windows but not for ASP.NET MVC Application.

Also, how does the domain name or host name affect the hosting.json file, etc?

Any help would be great.

kscott5 avatar Feb 02 '16 21:02 kscott5

I believe it is (though I'm not official; don't work for MS, and could be wrong)

Windows - Kestrel reversed proxied behind IIS with HttpPlatformHandler Linux - Kestrel reversed proxied behind nginx

With addition of at least to ngnix's reverse proxy config

proxy_http_version 1.1;
proxy_set_header Connection keep-alive;

benaadams avatar Feb 03 '16 04:02 benaadams

@DamianEdwards @glennc do we have any docs (in progress?) on production hosting?

Eilon avatar Feb 03 '16 06:02 Eilon

@benaadams There's on wrong answer just choices and some will be better than other. I got nginix running on Linux however, my application just hung. I will try the proxy settings you suggested.

@DamianEdwards I understand this is an Open Source Project but a little direction/recommendation would be helpful. Lol!

I'm curious how Kestrel will running in production environment. For instance as a services in the background on Linux OS.

I wonder if ServiceContext.cs could be used for this purpose. But it doesn't have the same contract the service command would use.

Better yet, I believe this could be the recommended way Issue 390.

kscott5 avatar Feb 03 '16 17:02 kscott5

@davidfowl @benaadams @DamianEdwards

I'm wonder if Docker is the best choice for hosting and running an ASP.NET application on Linux (Centos).

Any suggestion??

kscott5 avatar Feb 03 '16 20:02 kscott5

@kscott5 my community member take on it is

  • Multiple applications/sites at different domains sharing same ip address+port
    • Multiple Kestrel applications
    • Route using domain with reverse proxy e.g. IIS/ngnix
    • (Can use WebListerner on Windows; which does this natively via http.sys)
  • Multiple virtual directory applications on same path (e.g. /blog, /shop, /admin, /media)
    • Multiple Kestrel applications
    • Route using path with reverse proxy e.g. IIS/ngnix
    • (Can use WebListerner on Windows; which does this natively via http.sys)
  • Single application with exclusive ip+port use but open to the internet
    • At this time, use Kestrel behind established publicly hardened reverse proxy e.g. IIS/ngnix
    • Configure reverse proxy with limits
      • e.g. max headers, max upload, timeouts etc
      • Generally they come with sensible defaults.
  • Single application with exclusive ip+port use but not open to the internet
    • Can use Kestrel directly

For instance as a services in the background on Linux OS.

This definitely may fall into the last category; if its not one of the previous ones - and using with the newer dotnet cli approach when compiling you can have an executable for your service that that has Kestrel embedded within it.

Other examples for the last case would be

  • webapi or websocket service backend (not directly internet exposed)
  • inside container; with routing controlled externally (e.g. IIS/ngnix)
  • intranet site - not accessible to internet

The common trend here is either port sharing; or not being directly on a port that is directly accessible to the internet. Though the potential security risk is DoS rather than information exposure.

However, the official recommended approach by Microsoft is one that is also a fully supported one; e.g. you can phone them up and get support; help etc for it and also has a greater in depth analysis behind it; whereas this is just my opinion - so they are very different things :smile:

benaadams avatar Feb 03 '16 20:02 benaadams

Double disclaimer; just to make a point.

I am not a security professional and this is just my own personal current opinion; based on what I believe to be a safe conservative approach for anything business critical.

And you should certainly take any official documentation, advice or recommended scenarios from Microsoft over anything I've said here...

benaadams avatar Feb 03 '16 20:02 benaadams

Lol! @benaadams Got It!

kscott5 avatar Feb 03 '16 20:02 kscott5

Even in an intranet scenario I'd have it behind IIS or ngnix. Never ever trust your internal network. Treat it as a hostile network like you would the internet.

blowdart avatar Feb 03 '16 21:02 blowdart

@blowdart but have your honeypot servers have a hotline to HR?

benaadams avatar Feb 03 '16 21:02 benaadams

We're still building out our "official" guidance in this area, but as @benaadams points out, it really comes down to your particular scenario. There may be times when it makes sense to expose Kestrel directly, assuming you understand the caveats, just as it may sometimes make sense to expose node.exe directly. But for the vast majority of cases, we'll recommend you have a front-end web server that proxies to your application process (which is running Kestrel).

DamianEdwards avatar Feb 03 '16 21:02 DamianEdwards

But for the vast majority of cases, we'll recommend you have a front-end web server that proxies 
to your application process (which is running Kestrel).

@DamianEdwards I don't understand all the caveats but are you referring to nginx proxy that @benaadams mention above?

kscott5 avatar Feb 03 '16 22:02 kscott5

Yes, ngnix on linux

benaadams avatar Feb 04 '16 03:02 benaadams

Well, Accessing a docker container from Windows Host was a good place to look.

But the best help was the command 'docker-machine ls'. This gave me the VM Box/Container hosted ip address. From there I was able to access my site.

Thanks again!!!!

kscott5 avatar Feb 04 '16 23:02 kscott5

With all of the performance work you're doing with Kestrel, how does IIS figure into this in terms of performance? I'm assuming IIS can't give you anywhere near the performance that you are now getting via Kestrel, so what does that mean for perf when you are running Kestrel behind IIS (or nginx for that matter)?

RickStrahl avatar Jun 05 '16 03:06 RickStrahl

@RickStrahl we actively measure direct Kestrel performance on multiple platforms, and on Windows we also measure IIS+Kestrel, and on Linux we measure nginx+Kestrel. For the IIS case, we have an "in" with IIS because of the AspNetCoreModule - that's how Kestrel hooks into IIS. And we have more work planned there that we hope should get even better perf for IIS+Kestrel.

Eilon avatar Jun 07 '16 18:06 Eilon

Are those results (iis+kestrel, nginix+kestrel) published somewhere?

aL3891 avatar Jun 07 '16 18:06 aL3891

Thanks @Eilon. Can you point at any more info on what exactly AspNetCoreModule does? Is there a repo for it? I can't seem to find the native code.Nothing in the IISIntegration repo.

RickStrahl avatar Jun 07 '16 19:06 RickStrahl

@RickStrahl - AspNet Core Module is a reverse proxy. It's not open source at the moment. It is forked from httpPlatformHandler and replaces it (https://github.com/aspnet/Announcements/issues/164)

moozzyk avatar Jun 07 '16 20:06 moozzyk

It will be open sourced.

davidfowl avatar Jun 07 '16 20:06 davidfowl

Any info anywhere? After my IIS post a few days ago anumber of questions have come up exactly what still works in IIS and what doesn't. UrlRewrite, possible to use IIS for static hosting in the same site/virtual etc.

From what I can see the module takes over IIS completely and nothing runs in the IIS application.

RickStrahl avatar Jun 07 '16 20:06 RickStrahl