如何在同一 URL 下托管多个 .NET Core 应用程序? [英] How to host multiple .NET Core apps under the same URL?

查看:13
本文介绍了如何在同一 URL 下托管多个 .NET Core 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 ASP.NET Core 中构建一些网站(多个用户界面应用程序和一个 WebAPI 应用程序).它们都使用 WebAPI 协同工作.就我的问题而言,我们将它们称为 App1、App2 和 App3.我在 IIS 中托管我的网站.

I am building a few web sites in ASP.NET Core (multiple user interface applications and a WebAPI app). They all work together, utilising the WebAPI. For the purpose of my question we'll call them App1, App2 and App3. I am hosting my websites in IIS.

通常,在旧的 .NET Framework (4.5.1) 中,我会在 IIS 中拥有一个网站,其中包含多个 Web 应用程序来托管我的多个应用程序.像这样:

Typically, in the old .NET Framework (4.5.1), I would have one website in IIS, with multiple web apps to host my multiple applications. Like so:

  • WebSite1 - 在端口 443 上运行
    • 应用 1

    • WebSite1 - running on port 443
      • App1

      App2

      App3

      如果网站 (WebSite1) 在端口 443 上运行(使用 SSL 证书),这意味着所有应用程序都可以通过一个域 URL 访问,如下所示:

      If the website (WebSite1) runs on port 443 (using the SSL cert), that means all apps are accessible via one domain url as follows:

      https://www.myapp.com/App2/

      https://www.myapp.com/App3/

      在 URL 末尾使用不同的应用名称来识别它们.

      With different app names at the end of the URL to identify them.

      在托管新的 ASP.NET Core 应用程序时,我也在 IIS 中托管,并按照 ASP.NET Core 网站部署文档,将每个 .NET Core Web 应用程序托管在 IIS 内的不同站点中.

      When hosting the new ASP.NET Core applications, I host in IIS as well, and following the documentation for ASP.NET Core web site deployment, I host each .NET Core web app in a different site within IIS.

      因为我的所有网站都有一个域名,例如,https://www.example.com(我使用的是 SSL 证书),我必须为其他网站提供不同的端口.所以我最终得到了这样的结果:

      As I have one domain name for all my sites, for example, https://www.example.com (I'm using an SSL cert), I have to give the other websites different ports. So I end up with something like this:

      • WebSite1 - 在端口 443 上运行

      • WebSite1 - running on port 443

      WebSite2 - 在端口 444 上运行

      WebSite2 - running on port 444

      WebSite3 - 在端口 445 上运行

      WebSite3 - running on port 445

      然后可以通过这些域名 URL 访问所有这些应用:

      All of these apps are then accessible via these domain name URLs:

      https://www.example.com:444/

      https://www.example.com:445/

      我如何将 ASP.NET Core 应用程序作为不同的应用程序"托管在一个网站下,这意味着它们解析为相同的域名 (https://www.example.com 和正斜杠应用程序名称标识我们想要哪个应用程序)?或者,我如何使用我现在配置的端口并将它们全部路由,以便 App1 是 example.com/的默认值,App 2 是 example.com/app2/,App 3 是 example.com/app3/?

      How do I host ASP.NET Core applications all under one website as different "Applications", meaning they resolve to the same domain name (https://www.example.com and the forward slash app name identifies which app we want)? OR alternatively, how do I take what I have configured now with the ports and route them all so App1 is default for example.com/, App 2 is example.com/app2/, and App 3 is example.com/app3/?

      我是否完全错误地看待这个 .NET Core 部署?

      Am I looking at this .NET Core deployment completely the wrong way?

      推荐答案

      您可以使用反向代理为同一域中的多个 ASP Net Core 应用程序提供服务.
      使用 IIS 我不太确定,但您需要安装 URL Rewrite,然后按照 文档 由微软提供(也这个 应该有帮助).
      您还可以使用 nginx.html#location" rel="noreferrer">location 和 proxy_pass 如下:

      You could use a reverse proxy for serving multiple ASP Net Core application on the same domain.
      Using IIS I'm not quite sure but you need to install URL Rewrite and then follow the documentation provided by Microsoft (also this one should be helpful).
      You can also use nginx using location and proxy_pass as follow:

      ...
      Some nginx Configuration 
      location /App1 {
              proxy_pass http://127.0.0.1:443;
          }
      location /App2 {
              proxy_pass http://127.0.0.1:444;
          }
      location /App3 {
              proxy_pass http://127.0.0.1:445;
          }
      Other configurations...
      

      然后,每次您想向域中添加另一个 ASP Net 应用程序时,您都需要添加另一个位置,在不同的点上运行该应用程序并重新启动 nginx.

      And then, each time you want add another ASP Net application to your domain you'll need to add another location, run the application on a different point and restart nginx.

      这篇关于如何在同一 URL 下托管多个 .NET Core 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆