ASP.NET Core web apps use Kestral as a lightweight web server. Kestral can be used as an internet-facing server, but the reccomended production configuration is to use it with Apache, Nginx, or another secure, high-performance server as a reverse proxy.
The proxy will be listening for client HTTP requests on port 80 (the standard HTTP port). When a request is recieved, it will be forwarded to Kestral which will be listening on a loopback (localhost) port such as 127.0.0.1:5000.
These are the steps to publish an ASP.NET Core web app to a Linux server
Install the .NET Core SDK on the server
Configure the web app to use a database on the server
Deploy the web app's executable code to the web server
Configure a process management tool to help restart the web app.
1. Installing the .NET Core SDK on the server
The .NET Core runtime is a package that provides the resources to run any kind of .NET Core app, from console apps to web apps, on the server. Note that the CIT department's server, citstudent, is running the Linux Centos operating system.
Log into citstudent using a terminal app or SSH client Example: ssh
Add the dotnet product feed to the installer: sudo rpm
Install the SDK
sudo yum install dotnet-sdk-2.1
TODO: Add a description of the .NET Core runtime and an
explanation of how it works
2. Configuring an App to use MariaDB
The current version of MariaDB on citstudent as of 6/12/18 is 5.5.56
In your ASP.NET Core project, add an EntityFramework provider for MariaDB. Since MariaDB is binary compatibility with MySQL we can use a MySQL provider. One of the better providers is Pomelo.EntityFrameworkCore.MySQL. Add a reference to this to your project.
Add code to Startup.cs in the ConfigureServices method to add a service for MySQL services.AddDbContext<ApplicationDbContext>(options
In appsettings.json, add a connection string similar to this one: "MySqlConnection": "server=localhost;user id=brian;password=xxxxxxxx;database=MyDatabase;"
If you haven't already added migrations to your project, do it now:
migrations add InitialMigration
Create a database on the server. On citstudent type:
At the prompt type: CREATE DATABASE mydatabase
Note: a useful cross-platform free, open-source database manager is DBeaver
3. Deploying a web app
We will be doing a Framework
Dependent Deployment. This means that in a previous step we installed the .NET Core runtime so the it is available system-wide.
Deploying the App
Add code to create a database if it doesn't exist and to apply any pending migrations. This code goes in Starup.cs, in the Configure method: using (var serviceScope =
var context =
Exclude Application Insights from the code in the release build's publish folder (See Issue #13542 below) Add the line below to your .csproj
publish from the development environment on your local machine to package an app into a directory (folder) that will contain code that can run on the server. Example:
publish --configuration Release
Copy the directory above, which contains your application's executable code, to the server using a means of your choice such as ftp, scp,rsync, or a continuous integration server. Note: You should create
a sub-directory in your home directory for your web apps, in the example below I named it apps Example (assuming you are in the project directory on your local machine):
Testing the App This test will just be run on the server itself, the web pages won't be delivered over the internet
From the command line, run the app:
A typical response will be: Hosting environment: Production
Content root path: /home//apps/myapp Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down.
Use the text based browser, elinks, to view the web page:
4. Configuring a Reverse Proxy
Configure your app
Use the Forwarded Headers Middleware The middleware updates the Request.Scheme, using the X-Forwarded-Proto header, so that redirect URIs and other security policies work correctly. Add the code below to Startup.configure
before a call to UseAuthentication or similar authentication scheme middleware. app.UseForwardedHeaders(new ForwardedHeadersOptions
Issue with links
See Issues #1120 and #2302 in the references section below