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 on 0.0.0.0:5000 .
- 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>