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

6

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>
Sign up to request clarification or add additional context in comments.

3 Comments

yes its work for me. But without www extension, it by default go to 5001 port
@saswatsaubhagya if you're using https instead of http, the default port is 5001. Anyway, custom this configuration as you like :)
thanks, what about the kestrel service file, Do I need to have 1 file for each website running asp.net core?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.