Host multiple asp.net core web application under a single linux server

江枫思渺然 提交于 2020-08-09 21:07:06

问题


I am new to asp.net core. I read the whole Microsoft official document and able to host the application in Linux Apache server. But I want to host multiple asp.net core web applications under a single IP Address. Please, anyone have the solution post here.

Thanks in Advance


回答1:


The official document shows us a way to use Apache as a reverse proxy :

<VirtualHost *:*>
    RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
</VirtualHost>

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
    ServerName www.example.com
    ServerAlias *.example.com
    ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
    CustomLog ${APACHE_LOG_DIR}helloapp-access.log common
</VirtualHost>

Basically, this configuration will make Apache listens on *:80 and proxy any HttpRequest whose ServerName equals www.example.com to http://127.0.0.1:5000/.

This is how Apache used as an proxy to ASP.NET Core works.

As for your question, suppose you have two asp.net core web applications:

  1. the first one is called WebApp1 and listens on 0.0.0.0:5000 .
  2. and the other is called WebApp2 and listens on 0.0.0.0:6000 .

Your Apache server listens on 0.0.0.0:80. For any incoming http request,

  • when Host equals www.webapp1.org, proxy this request to 0.0.0.0:5000
  • when Host equals www.webapp2.org, proxy this request to 0.0.0.0:6000

So you could add two proxies :

proxy 1 :

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
    ServerName www.webapp1.org
    ServerAlias *.webapp1.org
    ErrorLog ${APACHE_LOG_DIR}webapp1-error.log
    CustomLog ${APACHE_LOG_DIR}webapp1-access.log common
</VirtualHost>

proxy 2 :

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:6000/
    ProxyPassReverse / http://127.0.0.1:6000/
    ServerName www.webapp2.org
    ServerAlias *.webapp2.org
    ErrorLog ${APACHE_LOG_DIR}webapp1-error.log
    CustomLog ${APACHE_LOG_DIR}webapp2-access.log common
</VirtualHost>


来源:https://stackoverflow.com/questions/54349357/host-multiple-asp-net-core-web-application-under-a-single-linux-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!