问题
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:
- the first one is called
WebApp1
and listens on0.0.0.0:5000
. - and the other is called
WebApp2
and listens on0.0.0.0:6000
.
Your Apache server listens on 0.0.0.0:80
. For any incoming http request,
- when
Host
equalswww.webapp1.org
, proxy this request to0.0.0.0:5000
- when
Host
equalswww.webapp2.org
, proxy this request to0.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