Posts

Showing posts with the label Linux

Deploy ASP NET Core application on Docker Linux container

Image
Deploy ASP NET Core application on Docker Linux container from Windows Few weeks ago we saw how we could run ASP NET Core application on Ubuntu . This proving that a .NET Core Application can run on a Linux system, today we will be taking it a step further and see how we can deploy our application in a Docker Linux container. This post will be composed by three parts: Install Docker on Windows Docker basic commands Create ASP NET Core application 1. Install Docker on Windows The first step is to go to the official site, sign up and download Docker CE . Once downloaded, install Docker. After being installed you should be able to right click on the icon > Settings on the Docker notification icon and see that Docker is running by checking the status at the bottom left, it should say Docker is running . Open PowerShell and type docker run hello-world . $ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world...

Inspect proxied requests from Nginx to Kestrel with Mitmproxy

Image
Inspect proxied requests from Nginx to Kestrel with Mitmproxy In previous blog posts, we saw how to proxy requests to an ASP NET Core application using Nginx . We saw that request headers also can be proxied with proxy_set_header In order to ease development, we need to be able to debug the values to verify that they are what we expect. Today we will see two methods to inspect the proxied requests. This post will be composed by two parts: Nginx location routing Nginx variable debugging Nginx proxied request debug with Mitmproxy 1 Nginx location routing Considering the following configuration of our server: server { listen 80; location / { proxy_pass http://localhost:5000; } location /api/ { proxy_pass http://localhost:5001/; } } If we want to check whether our location routes are properly configured, we can short circuit the proxy_pass with return and use curl to check whether the location is properly selected. server { listen ...

Manage configurations with ASP NET Core on Ubuntu

Manage configurations with ASP NET Core on Ubuntu Managing configurations can be challenging. We cannot simply check-in in our repository secrets and connection strings and at the same time we want an easy way to maintain them. Today we will see how we can manage secrets is am easy way on Ubuntu with systemd. Make secrets available on server with systemd Manage secrets locally with UserSecrets on ASP NET Core Manage UserSecrets for dotnet Console Application Goal We need to keep secrets out of the source code. Therefore we want to have our application get secrets locally for local testing and we want the application to get them in our hosted environment. In order to achieve that we will use systemd override configuration to hold configuration of secrets on our server and in our local machine we will use UserSecrets which holds configurations in the user app folder. Take note that UserSecrets file is not encrypted. The only protection we get is the OS user protection. If you...

Self Signed Certificate for Identity Server 4 and SSL in Ubuntu 16.04 server

Image
Self Signed Certificate for Identity Server 4 and SSL in Ubuntu 16.04 server To sign our JWT tokens, Identity Server 4 requires a signing credential. Today we will see how we can create our own key and provide it to Identity Server to be used as signing credential. Configure ASP NET Core Create key with openssl Selfsigned certificate for local SSL usage If you are new to Identity Server, you can have a look at my previous blog post on How to configure a Implicit authentication with Identity Server . 1. Configure ASP NET Core We start first by creating an extension on top of the IIdentityServerBuilder which when the key is available, will load our own key using the .AddSigningCredential() else will create a temporary key for development purposes, .AddDeveloperSigningCredential() . public static class IdentityServerBuilderExtensions { public static IIdentityServerBuilder LoadSigningCredentialFrom(this IIdentityServerBuilder builder, string path) { if (!string...

ASP NET Core with Nginx

ASP NET Core with Nginx Few weeks ago I showed how to host ASP NET Core on Windows Server behind IIS. Compared to Windows Server, Ubuntu with nginx offers a quicker way to get started and a better control over the kestrel process. Today we will see how to host an ASP NET Core application on Ubuntu. This post will be composed of three parts: Install nginx Configure nginx Host ASP NET Core 1. Install nginx Start by installing nginx. sudo apt-get update sudo apt-get install nginx After installing nginx, the daemon should have been installed and started. We should be able to navigate to http://localhost and see the nginx default page. This page is the default root folder of nginx which can be found under /var/www/html/ . We should also be able to interact with it just like any other daemon managed by systemd : sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl restart nginx sudo systemctl status nginx And similarly it can be debugged via journald : sudo jo...

Manage Kestrel process with systemd

Manage Kestrel process with systemd Kestrel is a lightweight standalone process. In order to host it on Linux, the recommended approach is to install it as a service. Systemd is a group of tools providing functionalities to manage processes on Ubuntu. Today we will see how we can manage an ASP NET Core application together with its Kestrel process using systemd tools. This post will be composed of three parts: Introduction Managing process with systemctl Debugging using journalctl 1. Introduction ASP NET Core application runs on top of Kestrel which is a lightweight standalone webserver. To be able to start to interact with our Ubuntu server we need to first establish an ssh connection. If you aren’t familiar with ssh, you can refer to my previous blog post where I provide explanations on how to setup ssh . Once we are on the server, we can get our libraries on the server and run: /usr/share/dotnet/dotnet myapp.dll This will run the app from the current session. When we ex...

Useful bash and friends commands

Useful bash and friends commands Since I have installed Ubuntu as a subsystem , I see myself using more and more bash. The reason being that all the VMs I spin up are Ubuntu VMs. My interactions with my servers are very basic but even for those, there are many beautiful commands which ease my interactions. Today I would like to go through the commands and tips which I use on a daily basis: ssh scp aliases less grep 1. ssh 1.1 Remote actions The ssh command allows us to remotly access a terminal or to execute commands remotly. For example when we create a new EC2 instance on AWS we can download the private key. This key can be used to ssh into the vm. ssh -i key.pem user:hostname -i is used to indicate the identity file to use. You might need to change the permissions on the file before it can be used with chmod 700 key.pem . It is also possible, to make life easier, to setup ssh to autodetect the private key file to use based on the host we are trying to access. We ca...