Host ASP.NET Core with Apache Using Webmin

Category: Web HostingTags: ,

If you are using Webmin to administer your Linux box, here are the steps to run ASP.NET Core application with Apache.


  • Ubuntu 18.04 / 20.04
  • Webmin

I assume that you have setup your server, Webmin and everything is up and running.

Install .Net Core

Here is a compilation of commands to install the .Net Core 3.1 on Ubuntu 18.04 / 20.04. Following is a list of commands without any clutter and specific for Webmin / Virtualmin setup.

Open a terminal with sudo user and execute following command to register Microsoft key

Following commands are for Ubuntu 18.04

wget -q -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb 

Following commands are for Ubuntu 20.04

wget -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb 

Now install .Net Core 3.1 and ASP.NET Core 3.1

sudo add-apt-repository universe 
sudo apt-get install dotnet-runtime-3.1 
sudo apt-get install aspnetcore-runtime-3.1 

If you want to install other .Net Core version, follow the main tutorial to get the correct command.

Setup .Net Core Website

Using Webmin, create a new Virtual Server. It would create a new folder “/home/Your_Virtual_Server”. Here create a new folder called “netcore_ Your_Virtual_Server” and upload and configure your .Net Core application to this folder.

Using terminal, navigate to this folder and execute the following command to quickly verify if everything is working as expected or not.

cd "/home/Your_Virtual_Server/netcore_Your_Virtual_Server"
dotnet "YourApp.dll"

Above command runs the application on http://localhost:5000 address by default. You can press “Ctrl+C” to terminate this application but continue running the application.

Setup Apache

While the dotnet core application is running, we want to setup Apache.

Go to Webmin > Servers > Apache Webserver on left hand side menu.

Click on “Global Configuration” tab > Edit Config Files > Select your Virtual Server Config file from the list.

Under <VirtualHost> tab, add following settings to use proxy

RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
ProxyPreserveHost On
ProxyPass /.well-known !
ProxyPass /
ProxyPassReverse /

Above settings sets the special header, excludes Let’s Encrypt SSL request and forwards all other requests to the dotnet core application running on

If you have SSL enabled for this virtual server, Webmin creates two <VirtualHost> tags – one for non secure and another one for secure site. Add above settings for both <VirtualHost> tags.

Save the changes and go back to the screen.

Top right corner shows a button to apply the changes. Click on the button and Apache will apply changes.

Now try to visit your website in a browser and you will get response from dotnet core application.

At this moment, your dotnet core application is working as expected so now in open terminal press “Ctrl+C” to terminate the dotnet core application that was running.

Monitor the application

In above portion, you have manually ran the application but now we want this application managed by Linux. For this, we need to create service.

Create a service file “/etc/systemd/system/kestrel-Your_Virtual_Server_APP.service” using Webmin. Change the file name “kestrel-Your_Virtual_Server_APP.service” as per your need.

Open the service file in Webmin and paste following text. Make change to the file as per your need

Description= Your_Virtual_Server_APP .Net Core 3.1 App

ExecStart=/usr/local/bin/dotnet /home/Your_Virtual_Server/netcore_Your_Virtual_Server/YourApp.dll
Restart service after 10 seconds if the dotnet service crashes:


In above text, change Description, WorkingDirectory, ExecStart, SyslogIdentifier and User as per your configuration.

Enable service by executing following command using sudo user at terminal

sudo systemctl enable kestrel-Your_Virtual_Server_APP.service

At this moment, your service is enable. Now go to Webmin > System > Bootup and Shutdown.

Here you will see your service in a list. Select your service by clicking on a checkbox. Go all the way down and click on “Start on Boot” in order to start this service on bootup. Again select this service and click on “Start” button to start your service.

You are all set and now your .net core application is happily running behind the Apache proxy.

If for any reason, you face any problem with starting the kestrel application, use the following command to get the log

sudo journalctl -fu kestrel-Your_Virtual_Server_APP.service --since today



Your email address will not be published. Required fields are marked *

  1. Marcio says:

    Hello! How may I host two .net core application using Apache?

    I’ve tried to use two kestrel services (up and running) and two virtual hosts.

    First on 5000 port and second on 5001 port, but I have no success, both on 80 port.


    1. Hello Marcio,

      Once you create two separate services on port 5000 and port 5001, you need to setup two individual virtual servers. Both of these virtual servers are either separate domains or separate subdomains. Use each virtual server as a reverse proxy for your .net core application. This way, both virtual servers will run on port 80.

      Generally it is not a good idea to directly expose .net core application to outside world on port 5000 and 5001. But if you really need it that way, you need to open those ports within your server firewall.

      Vishal Monpara