After we successfully installed and configured XFCE on Ubuntu 14.04 and ASP.NET Core 1.0 in part 1 of this tutorial, we have to add NGINX to expose our great Hello World app to the internet. As I mentioned in part I, it’s not advisable to expose Kestrel directly, since it’s not meant to be used like that and has lot of limitation as a front-end web server: handling of multiple host names, authentication, HTTPS offloading, caching, just to mention few.

Nginx will receive requests for specific host name (we’ll point subdomain or domain to our Azure VM) and route them to internal Kestrel URL (localhost:5000 in this example). This configuration is called Reverse Proxy. Same thing can be done also with IIS Application Request and Routing module on Windows.

Point DNS to Azure VM

Let’s start with updating our DNS records. Open your DNS provider-of-choice and add CNAME record that points to Azure VM DNS name. Azure usually creates name like myvmname.westeurope.cloudapp.azure.com. Here, I created subdomain on this blog domain: http://coretest.hudosvibe.net

If you don’t want to update DNS records, then just edit you OS hosts file and point subdomain.domain.com to IP address of this Azure server!

NGINX installation

SSH into your VM or RDP into XFCE, and open bash. To install nginx type:

sudo apt-get updatesudo apt-get install nginx

If you open your browser and type Azure DNS name or subdomain into address bar, nginx welcome page should open! From within VM, you can try to open (with Midori) http://localhost, the same welcome page should open (the same web opened from my dev machine and from Ubuntu with Midori):

NGINX Reverse proxy to Kestrel server configuration

Open your favorite editor (nano, geany) as sudo, create a new file with the content (again, change sub/domain name):

server { listen 80; listen [::]:80;

server_name subdomain.domain.com;

location / { proxy_pass http://localhost:5000; }}

This will forward all requests to internal Kestrel web server that’s listening on the port 5000 (it’s started with dotnet run, right?).

Save the file as /etc/nginx/sites-available/subdomain.domain.com

We have to enable this website, and that’s done by creating a link to that file in /etc/nginx/sites-enabled:

Here are few tips how to create and run ASP.NET Core application under Linux (Ubuntu 14.04 LTS), on a cheap Azure VM (0.75GB RAM, 0.25 CPU cores). Windows Server requires a little bit more memory (way around that is to increase the size while you're configuring the machine, and then lower it while not working in RDP).

Goals of this exercise are:

Cheap Azure VM with Linux (around 10-15$/month). There are other hosting option, for example on Hetzner, for ~5€/m

TIP: to use bash and ssh from windows, there are few options: new native Bash on Win10, Git bash, or putty. They all have ssh.Open bash and type this to ssh into new linux vm: ssh -l username IP/DNS name

Also, it's useful to assign DNS name to that machine, to avoid using dynamic IP address.

You should be able to RDP into the machine now! First time I got some error with "connection error", but I tried again immediately, and was able to RDP and log in into XFCE.

We can now install two apps:

Midori web browser (open terminal, type sudo apt-get install midori)

Geany text editor (in terminal type sudo apt-get install geany. It will be installed under /usr/bin folder. If you navigate there with file browser, you can right click to it and choose Send To/Desktop Create Link). Btw, don’t expect code completion, it's just syntax highlighting. And if you feel brave enough, there’s always VIM. Purpose of installing text editor is not to develop an app on web server, but just to edit configuration files!

Executing dotnet run will start Kestel, and sample page can be opened in Midori! Happy days!

XFCE running with Midori, Kestrel, Geany takes around 70% of 0.75GB RAM, which is OK for playing with new dotnet and even running small-medium websites in production.

Next blog post will explain how to put Nginx in front of kestrel, since that's recommended production configuration (that's how node and other platforms are exposed to internet, there is always some reverse proxy in front of platform web server – kestrel doesn't know how to cache, authenticate request, handle https, etc)