何時搭配使用 Kestrel 與反向 ProxyWhen to use Kestrel with a reverse proxy

您可以單獨使用 Kestrel,或與 Internet Information Services (IIS)NginxApache 等「反向 Proxy 伺服器」搭配使用。Kestrel can be used by itself or with a reverse proxy server, such as Internet Information Services (IIS), Nginx, or Apache. 反向 Proxy 伺服器會從網路接收 HTTP 要求,然後轉送到 Kestrel。A reverse proxy server receives HTTP requests from the network and forwards them to Kestrel.

Kestrel 用作邊緣 (網際網路對應) 網頁伺服器:Kestrel used as an edge (Internet-facing) web server:

Kestrel 不使用反向 Proxy 伺服器直接與網際網路通訊

Kestrel 用於反向 Proxy 組態中:Kestrel used in a reverse proxy configuration:

Kestrel 透過 IIS、Nginx 或 Apache 等反向 Proxy 伺服器間接與網際網路通訊

不論是否有反向 proxy 伺服器,設定都是支援的裝載設定。Either configuration, with or without a reverse proxy server, is a supported hosting configuration.

使用 Kestrel 做為沒有反向 proxy 伺服器的 edge server 時,不支援在多個進程之間共用相同的 IP 位址和埠。When Kestrel is used as an edge server without a reverse proxy server, sharing of the same IP address and port among multiple processes is unsupported. 當 Kestrel 設定為接聽埠時,Kestrel 會處理該埠的所有流量,而不論要求的 Host 標頭為何。When Kestrel is configured to listen on a port, Kestrel handles all traffic for that port regardless of requests' Host headers. 可以共用埠的反向 proxy 可以將要求轉送至唯一 IP 和埠上的 Kestrel。A reverse proxy that can share ports can forward requests to Kestrel on a unique IP and port.

即使不需要反向 Proxy 伺服器,使用反向 Proxy 伺服器也是不錯的選擇。Even if a reverse proxy server isn't required, using a reverse proxy server might be a good choice.

反向 Proxy:A reverse proxy:

  • 可以限制它所主控之應用程式的公開介面區。Can limit the exposed public surface area of the apps that it hosts.
  • 提供額外的組態和防禦層。Provide an additional layer of configuration and defense.
  • 能夠與現有基礎結構更好地整合。Might integrate better with existing infrastructure.
  • 簡化負載平衡和安全通訊 (HTTPS) 組態。Simplify load balancing and secure communication (HTTPS) configuration. 只有反向 proxy 伺服器需要 x.509 憑證,而且該伺服器可以使用一般 HTTP 與內部網路上的應用程式伺服器進行通訊。Only the reverse proxy server requires an X.509 certificate, and that server can communicate with the app's servers on the internal network using plain HTTP.

警告

裝載於反向 Proxy 組態需要主機篩選Hosting in a reverse proxy configuration requires host filtering.

其他資源Additional resources

設定 ASP.NET Core 以與 Proxy 伺服器和負載平衡器搭配運作