2

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 Answer 1

5

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>
3
  • yes its work for me. But without www extension, it by default go to 5001 port Jan 28, 2019 at 6:52
  • @saswatsaubhagya if you're using https instead of http, the default port is 5001. Anyway, custom this configuration as you like :)
    – itminus
    Jan 28, 2019 at 10:23
  • 1
    thanks, what about the kestrel service file, Do I need to have 1 file for each website running asp.net core?
    – RollRoll
    May 10, 2020 at 11:20

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.