如何在同一URL下托管多个.NET Core应用 [英] How to host multiple .NET Core apps under same url
问题描述
我正在asp.net核心中构建一些网站(多个用户界面应用程序和一个Web api应用程序).他们都利用Web API一起工作.就我的问题而言,我们将其称为App1,App2和App3.我将网站托管在IIS中.
I am building a few web sites in asp.net core (multiple user interface applications and a web api app). They all work together, utilising the web api. 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上运行
WebSite1 - running on port 443
-
App1
App1
App2
App3
如果网站(WebSite1)在端口443上运行(使用SSL证书),则意味着可以通过一个域网址访问所有应用,如下所示:
If the website (WebSite1) runs on port 443 (using the SSL cert), that means all apps are accessible via one domain url as follows:
在网址末尾使用不同的应用名称来标识它们.
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
然后可以通过以下域名网址访问所有这些应用程序:
All of these apps are then accessible via these domain name urls:
-
https://www.example.com/或 https://www.example.com:444/
我如何将一个网站上的asp.NET Core应用程序托管为不同的应用程序",这意味着它们解析为相同的域名url(
How do I host asp.NET Core applications all under one website as different "Applications", meaning they resolve to the same domain name url (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>位置和 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屋!