简体   繁体   English

Asp.Net Core中的反向代理和进程内HTTP服务器

[英]Reverse proxy and in-process HTTP server in Asp.Net Core

I was reading about Kestrel web server in asp.net core app specifically the in-process http server and reverse proxy . 我正在阅读asp.net core app Kestrel web服务器,特别是in-process http serverreverse proxy

Being a seasonal web developer, I have trouble in understanding the idea behind: 作为季节性的Web开发人员,我无法理解背后的想法:

  • The relevance of a in-process http server implementation in core application ? in-process http server实现在核心应用程序中的相关性?
  • The importance of reverse proxy approach over any typical web server ? 反向代理方法对任何典型web server的重要性?
  • The type of issues does a reverse proxy solve in asp.net core world other than forwarding http request ? 除了转发http request之外,问题的类型是否在asp.net核心世界中解决了反向代理问题?
  • How reverse proxy and Kestrel correlate / communicate ( 1:n or 1:1 ) if the asp.net core app is meant to be deployed in a container? 如果asp.net核心应用程序要部署在容器中, reverse proxyKestrel如何关联/通信( 1:n1:1 )?

According to official documentation : 根据官方文件

ASP.NET Core was designed to run in its own process so that it can behave consistently across platforms. ASP.NET Core旨在在其自己的进程中运行,以便它可以跨平台一致地运行。 IIS, Nginx, and Apache dictate their own startup process and environment; IIS,Nginx和Apache决定了他们自己的启动过程和环境; to use them directly, ASP.NET Core would have to adapt to the needs of each one. 要直接使用它们,ASP.NET Core必须适应每个人的需求。 Using a web server implementation such as Kestrel gives ASP.NET Core control over the startup process and environment. 使用诸如Kestrel之类的Web服务器实现为ASP.NET Core提供了对启动过程和环境的控制。 So rather than trying to adapt ASP.NET Core to IIS, Nginx, or Apache, you just set up those web servers to proxy requests to Kestrel. 因此,您只需将这些Web服务器设置为代理对Kestrel的请求,而不是尝试将ASP.NET Core调整为IIS,Nginx或Apache。 This arrangement allows your Program.Main and Startup classes to be essentially the same no matter where you deploy. 无论您在何处部署,这种安排都允许您的Program.Main和Startup类基本相同。

Besides that having the in-process http server makes stuff really easier for developers. 除了具有进程内http服务器使开发人员更容易使用的东西。 They just download the framework, install it and it works out of the box no matter what OS they are using (Windows, Linux or MacOS) or what web server they want to use later. 他们只是下载框架,安装它,无论他们使用什么操作系统(Windows,Linux或MacOS)或他们想要在以后使用什么Web服务器,它都可以开箱即用。 They just fire dotnet run command which starts the http server with a web app hosting on it. 他们只是启动了dotnet run命令,启动了http服务器并在其上托管了一个Web应用程序。

While it's OK to run it in a development environment when an app is ready for production developers should remember about security. 虽然在应用程序准备好生产时在开发环境中运行它是可以的,但开发人员应该记住安全性。 The Kestrel web server is very new web server so it doesn't have all that security and other useful features as IIS, Apache or Nginx obtained during their long lives. Kestrel Web服务器是一个非常新的Web服务器,因此它不具备IIS,Apache或Nginx在其长寿期间获得的所有安全性和其他有用功能。 This is the only reason why MS recommends to use reverse-proxy in production environment. 这是MS建议在生产环境中使用反向代理的唯一原因。 The goal of reverse proxy is not only forward requests to in-process http server, but also be responsible for security, compression and other features a good web server may provide. 反向代理的目标不仅是对进程内http服务器的转发请求,而且还负责安全性,压缩和良好的Web服务器可能提供的其他功能。

As for container deployments it really depends on what you want to achieve. 至于容器部署,它实际上取决于您想要实现的目标。 There are different scenarios: 有不同的场景:

  • Run ASP.NET Core app and reverse proxy in the same container. 在同一容器中运行ASP.NET Core应用程序和反向代理。 In this case ASP.NET core app is usually configured to run on a local port eg 5000, while a reverse proxy binds to port 80. This approach is not generally recommended because as best practices say "Each container should have only one concern" 在这种情况下,ASP.NET核心应用程序通常配置为在本地端口(例如5000)上运行,而反向代理绑定到端口80.通常不推荐这种方法,因为最佳实践说“每个容器应该只有一个问题”
  • Run a reverse-proxy and ASP.NET Core app in 2 different containers. 在2个不同的容器中运行反向代理和ASP.NET Core应用程序。 In this case you have to link these containers to each other in order to forward requests from a reverse-proxy to a web app. 在这种情况下,您必须将这些容器相互链接,以便将请求从反向代理转发到Web应用程序。
  • Run a reverse proxy on one container and configure it to be a reverse proxy for multiple ASP.NET core app containers. 在一个容器上运行反向代理,并将其配置为多个ASP.NET核心应用程序容器的反向代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM