Discount for my course: High Performance Coding with .NET Core and C#

Gergely Kalapos

Hosting ASP.NET Core behind Apache on Ubuntu

Posted on October 18, 2016

The official documentation for hosting on Linux only describes how to host ASP.NET Core apps behind nginx. Here is a short summary about the same for Apache.

So, first of all just running the app and let kestrel do everything is technically possible, but not recommended: according to MS you should use a proper web server and reverse proxy to kestrel.

If you want to host your site behind Apache from whatever reason you can follow the official documentation and replace the nginx related steps with these steps:

Install Apache and make sure you get the default page (there are many great tutorials on this).

Install the the necessary apache modules by running these commands:

sudo a2enmod proxy_html
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_ajp
sudo a2enmod rewrite
sudo a2enmod deflate
sudo a2enmod headers
sudo a2enmod proxy_balancer
sudo a2enmod proxy_connect

Modify the /etc/apache2/sites-enabled/000-default.conf file to reverse proxy to the ASP.NET Core app like this:


<VirtualHost *:80>
        ProxyPreserveHost On
        ProxyPass /
        ProxyPassReverse /

In this case we forward everything to localhost:5000.

Then start your ASP.NET Core app. As the official documentation suggests I use supervisor, which makes sure that the process always runs.

That’s it! I did not find anything on this topic, so hopefully this will help others.