Hosting Multiple ASP.NET Core Apps in Ubuntu Linux Server Using Apache
Tags: linux, csharp, dotnet, webdev
Published: 2021-08-19 12:11:47

---
title: Hosting Multiple ASP.NET Core Apps in Ubuntu Linux Server Using Apache
published: true
date: 2021-08-19 11:12:25 UTC
tags: linux, csharp, dotnet, webdev
canonical_url: https://www.syncfusion.com/blogs/post/hosting-multiple-asp-net-core-apps-in-ubuntu-linux-server-using-apache.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ovisvexr6igxolbmhwm.png
---

[ASP.NET Core](https://en.wikipedia.org/wiki/ASP.NET_Core "Link to the Wikipedia page for ASP.NET Core") is a cross-platform web development framework that supports developing applications on Windows, Mac, Linux, iOS, and Android platforms. Hosting an ASP.NET Core application in Linux is complicated when compared to hosting one in Windows. In this article, I will explain how to easily host multiple ASP.NET Core apps in [Ubuntu Linux server](https://ubuntu.com/server "Link to the Ubuntu Linux Server") with [Apache](https://httpd.apache.org/ "Link to the APACHE HTTP SERVER PROJECT") as a reverse proxy server.

Let’s get started!

## Connect to the Linux server

For this blog post, let’s assume you are using a Windows machine to develop the ASP.NET Core application. We are going to connect the Windows machine to a Linux server using the [PuTTY](https://www.putty.org/ "Link to download PuTTY"). Provide the server IP address and the root password in the **PuTTY Configuration** dialog to connect to the Linux machine.

![PuTTY Configuration](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/PuTTY-Configuration-1.png)

![Provide the server IP address and root password](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Provide-the-server-IP-address-and-root-password.png)

## Install the necessary dependencies and .NET Core Framework

Next, download and install the .NET Core Framework to host the ASP.NET Core application in the Linux Ubuntu server. Before installing the .NET Framework, we need to install its dependencies.

1. Copy and paste the following command in PuTTY to install the dependencies:  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">wget https://packages.microsoft.com/config/ubuntu/19.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb</code></td>
</tr>
</tbody>
</table>

![Command to be copied and pasted in the PuTTY](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Command-to-be-copied-and-pasted-in-the-PuTTY.png)

2. Now, install the ASP.NET Core runtime network that is used to run the publishing app. Read the [supported distributions in Linux documentation](https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#supported-distributions "Link to supported distributions in Linux") before installing it. Here, I have installed the ASP.NET Core 3.1 version.  
Refer to the following commands.

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">sudo apt-get update; \
sudo apt-get install -y apt-transport-https &amp;&amp; \
sudo apt-get update &amp;&amp; \
sudo apt-get install -y aspnetcore-runtime-3.1</code></td>
</tr>
</tbody>
</table>

### Install the Apache server

Apache server will act as a reverse proxy and pass the request to the [Kestrel Server](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-5.0 "Link to Kestrel web server implementation in ASP.NET Core") from the internet.

1. Let’s install the [Apache server](https://httpd.apache.org/ "Link to the APACHE HTTP SERVER PROJECT") in the Linux machine using the following command:  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">sudo apt install apache2</code></td>
</tr>
</tbody>
</table>

2. After installing the Apache Server, install the following required modules:  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod headers
sudo a2enmod ssl</code></td>
</tr>
</tbody>
</table>

3. Now, restart the Apache server using the following command:  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">sudo service apache2 restart</code></td>
</tr>
</tbody>
</table>

## Move the application files to the Linux server

Follow these steps to move your ASP.NET Core application files to the Linux server.

1. Publish the ASP.NET Core application you want to host to a local folder.  
 ![Publish the ASP.NET Core application](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Publish-the-ASP.NET-Core-application.png)
2. Then, connect to the Linux Server using [FileZilla](https://filezilla-project.org/ "Link to the FileZilla") to move the published files. Open the folder **/var/www** in the Linux server.
3. Create a new folder named **sample** and then move the published files to it.  
 ![Create a new folder named sample and then move the published files to this new folder](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Create-a-new-folder-named-sample-and-then-move-the-published-files-to-this-new-folder.png)

## Create a service to run the application

Now, we are going to create a service file to run the ASP.NET Core application.

1. To do so, create a service file named **sample.service** and add the following configuration to it:  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">[Unit]
Description=Running ASP.NET Core on Ubuntu 18.04 Webserver APACHE
[Service]
WorkingDirectory=/var/www/sample/
ExecStart=/usr/bin/dotnet /var/www/sample/sample.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target</code></td>
</tr>
</tbody>
</table>

![Command to be added in the service file named sample.service](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Command-to-be-added-in-the-service-file-named-sample.service.png)In the above configuration,

  - **WorkingDirectory** defines the folder from which the service will run.
  - **ExecStart** defines the application to be started in this service.
2. Then, move the newly created file to the Linux server in the location **etc/systemd/system/** using FileZilla. Enable and start the service using the following command in PuTTY:  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">sudo systemctl enable sample.service
sudo systemctl start sample.service</code></td>
</tr>
</tbody>
</table>

## Create a host configuration file

1. Create a new host configuration file named **sample.conf** and add the following configuration to it:  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">&lt;VirtualHost *:80&gt;
ServerName www.sample.com
ProxyPreserveHost On
ProxyPass / http:// 127.0.0.1:5000/
ProxyPassReverse / http:// 127.0.0.1:5000/
ErrorLog ${APACHE_LOG_DIR}/sample-error.log
&lt;/VirtualHost&gt;</code></td>
</tr>
</tbody>
</table>

In the above configuration:

  - **VirtualHost \*:80**  means that the site is hosted under port 80.
  - Domain URL is given in the **ServerName**.
  - For **proxypass** and **proxypassreverse** , we have provided the Kestrel server that is running locally and its default port is 5000.
2. All the application’s config files are located in the file path **etc/apache2/sites-available** in the Linux server. So, move the created config file to the Linux server under this folder.
3. Now, enable the new site configuration using the following command:  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">sudo a2ensite sample.conf</code></td>
</tr>
</tbody>
</table>

4. Check the syntax of the configuration using the following command:  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">sudo apachectl configtest</code></td>
</tr>
</tbody>
</table>

If there is no error, then your site is ready to go!

## Hosting multiple ASP.NET Core applications

We have seen how to create a service and config file to host an ASP.NET Core application in a Linux server. Now, let’s see how you can host another application on the same Linux server. To do so, follow these steps:

1. Move the new application sample to the Linux server under the file path **/var/www/sample1**.
2. Then, create a new service file named  **sample1.service** and add the following configuration to it. Here, we will add the port from which the new sample application will be hosted.  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">[Unit]
Description=Running ASP.NET Core on Ubuntu 18.04 Webserver APACHE
[Service]
WorkingDirectory=/var/www/sample/
ExecStart=/usr/bin/dotnet /var/www/sample/sample.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
Environment=ASPNETCORE_URLS=http://127.0.0.1:5001
[Install]
WantedBy=multi-user.target</code></td>
</tr>
</tbody>
</table>

3. Move the service and enable it by following the steps given in the [Create a service to Run the application section](#create-a-servecie-to-run-the-application).
4. Now, create a new host configuration file named **sample1.conf** and add the following command to it. Here, for proxy, use the new port 5001.  

<table style="margin-left: 40px;" width="0">
<tbody>
<tr>
<td><code class="markup--code markup--p-code">&lt;ltVirtualHost *:80&gt;
ServerName www.sample1.com
ProxyPreserveHost On
ProxyPass / http:// 127.0.0.1:5001/
ProxyPassReverse / http:// 127.0.0.1:5001/
ErrorLog ${APACHE_LOG_DIR}/sample-error.log
&lt;/VirtualHost&gt;</code></td>
</tr>
</tbody>
</table>

5. Finally, move the .conf file to the Linux server and then enable the site. Now, you can access the new hosted application.

**Note: ** Similarly, you can host any number of applications using the app’s port in the Linux server.

## Conclusion

Thanks for reading! In this blog post, we have seen how to host multiple ASP.NET Core applications in a Linux Ubuntu server using Apache as a reverse proxy. With this approach, hosting an ASP.NET Core app in Linux isn’t complicated. So, try out the steps provided in this blog post and leave your feedback in the comments section.

The Syncfusion [ASP.NET Core UI controls](https://www.syncfusion.com/aspnet-core-ui-controls "Link to ASP.NET Core UI controls") library powered by [Essential JS 2](https://www.syncfusion.com/javascript-ui-controls "Link to the Essential JS 2 UI controls") is the only suite that you will ever need to build an application since it contains over 70 high-performance, lightweight, modular, and responsive UI controls in a single package. Use them to increase your productivity in app development!

If you’re already a Syncfusion user, you can download the [product setup](https://www.syncfusion.com/account/downloads/studio/ "Link to license and download page of Essential Studio"), or, you can download a free [30-day trial ](https://www.syncfusion.com/account/downloads/studio "Link to the free evaluation of the Syncfusion Essential Studio")to evaluate our products.

You can also contact us through our [support forum](https://www.syncfusion.com/forums "Link to the Syncfusion support forum"), [Direct-Trac](https://www.syncfusion.com/account/login "Link to the Syncfusion support system Direct Trac"), or [feedback portal](https://www.syncfusion.com/feedback/ "Link to Syncfusion Feedback Portal"). As always, we are happy to assist you!

## Related blogs

- [Easy Steps to Migrate an ASP.NET MVC Project to ASP.NET Core Project](https://dev.to/karthickramasamy08/easy-steps-to-migrate-an-asp-net-mvc-project-to-asp-net-core-project-2phe-temp-slug-6273032 "Link to Easy Steps to Migrate an ASP.NET MVC Project to an ASP.NET Core Project blog")
- [How to Use Localization in an ASP.NET Core Web API](https://dev.to/syncfusion/how-to-use-localization-in-an-asp-net-core-web-api-3onb "Link to How to Use Localization in an ASP.NET Core Web API blog")
- [Easy Steps to Integrate ASOS in ASP.NET Core API](https://dev.to/syncfusion/easy-steps-to-integrate-asos-in-asp-net-core-api-4p6j "Link to Easy Steps to Integrate ASOS in ASP.NET Core API blog")
- [Creating the Story Estimator application with Syncfusion ASP.NET Core Controls](https://www.syncfusion.com/blogs/post/story-estimator-with-syncfusion-asp-net-core-controls.aspx "Link to Creating a Story Estimator Application with Syncfusion ASP.NET Core Controls blog")