<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Rebin</title>
    <description>The latest articles on Forem by Rebin (@rebiiin).</description>
    <link>https://forem.com/rebiiin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F409701%2Fac45db40-4ab9-4e29-8d90-1c61e5ef2941.png</url>
      <title>Forem: Rebin</title>
      <link>https://forem.com/rebiiin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rebiiin"/>
    <language>en</language>
    <item>
      <title>Configure HTTP security response headers for Azure Static Web Apps</title>
      <dc:creator>Rebin</dc:creator>
      <pubDate>Mon, 06 Sep 2021 19:48:08 +0000</pubDate>
      <link>https://forem.com/rebiiin/configure-http-security-response-headers-for-azure-static-web-apps-2b81</link>
      <guid>https://forem.com/rebiiin/configure-http-security-response-headers-for-azure-static-web-apps-2b81</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;HTTP security headers is the most crucial part of the web applications that helps to protect against some variety of attacks most likely cross-site scripting, clickjacking and other script attacks, configure HTTP security headers is frequently forgotten by Developers! So, I recently checked my blog on &lt;a href="https://securityheaders.com" rel="noopener noreferrer"&gt;securityheaders.com&lt;/a&gt; and results indicated that HTTP security headers are not configured so I decided to put some HTTP security headers for my Azure Static Web Apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recommended HTTP security headers
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Strict-Transport-Security&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Content-Security-Policy&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;X-Frame-Options&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;X-Permitted-Cross-Domain-Policies&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;X-Content-Type-Options&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Permissions-Policy&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Configure HTTP security headers
&lt;/h3&gt;

&lt;p&gt;You can create a json file called ( staticwebapp.config.json ) in the root of the web site and put the configuration like below then deploy it to your Azure Static Web App host.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"globalHeaders"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"content-security-policy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"frame-ancestors 'self'; 
         upgrade-insecure-requests"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"X-Frame-Options"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SAMEORIGIN"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"X-Permitted-Cross-Domain-Policies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"none"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Referrer-Policy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"no-referrer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"X-Content-Type-Options"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nosniff"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Permissions-Policy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"autoplay=()"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>azure</category>
      <category>security</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Install ASP.NET Core on Linux Azure Virtual Machine Ubuntu 18.04 LTS</title>
      <dc:creator>Rebin</dc:creator>
      <pubDate>Thu, 25 Jun 2020 18:56:38 +0000</pubDate>
      <link>https://forem.com/rebiiin/install-asp-net-core-on-linux-azure-virtual-machine-ubuntu-18-04-lts-1766</link>
      <guid>https://forem.com/rebiiin/install-asp-net-core-on-linux-azure-virtual-machine-ubuntu-18-04-lts-1766</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As we know ASP.NET Core is one of the best open source frameworks it used to build a modern web applications and that has the most users in the world wide today the reason is that a significant change has been made to it is that it will work very good and more efficiently on many types of Linux distributions as well as on Windows and Mac operating systems that is why it is called cross-platform. Obviously, we want our app to have the best performance and reliable so in this article I am going to explaining how to install Asp.Net Core and configure Nginx web server on Azure Linux Virtual Machine (Ubuntu 18.4).&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's get started
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Step 1 : Connect to Azure Linux Virtual Machine
&lt;/h2&gt;

&lt;p&gt;Putty terminal emulator is used to connect with Virtual Machine as well as run some commands to perform tasks, after you have connected with the Ubuntu Linux VM you will see something like this now we are ready to achieve our goals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F10laz8idz2jg2fhooeh3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F10laz8idz2jg2fhooeh3.png" alt="SSH-VM" width="800" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 : Register Microsoft key and repository feed
&lt;/h2&gt;

&lt;p&gt;Before we dive into installing .Net Core we will need to register the Microsoft key register the product repository on Linux Ubuntu We run the following commands to register it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb Jump &lt;span class="nt"&gt;-O&lt;/span&gt; packages-microsoft-prod.deb

&lt;span class="nb"&gt;sudo &lt;/span&gt;dpkg &lt;span class="nt"&gt;-i&lt;/span&gt; packages-microsoft-prod.deb

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4rvkp1zp2t7e3vgxd5vh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4rvkp1zp2t7e3vgxd5vh.png" alt="RegisterKeyFeed" width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 : Install .NET Core
&lt;/h2&gt;

&lt;p&gt;There are two types of .Net Core is available SDK and Runtime the difference between them is that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The SDK includes everything you need to build and run .NET Core applications by using command line, tools and any editor (like Visual Studio) as well as .Net Core runtime type has included in this type.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The runtime includes everything you need to run .NET Core applications that allows you to run apps that were made with .NET Core (already created and compiled).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install .Net Core SDK is also include runtime so run the following commands to install it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; apt-transport-https &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; dotnet-sdk-3.1

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make sure everything is fine run the following commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
dotnet &lt;span class="nt"&gt;--info&lt;/span&gt;

&lt;span class="c"&gt;# Or run this command to get dotnet core version&lt;/span&gt;

dotnet &lt;span class="nt"&gt;--version&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the .Net Core SDK successfully installed on Linux Ubuntu 18.4.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh98784l1lrw8uwhjw2w7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh98784l1lrw8uwhjw2w7.png" alt="Alt Text" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 : Install Nginx Web Server
&lt;/h2&gt;

&lt;p&gt;Why choose Nginx as a Web Server ?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities a reverse proxy and load balancer for HTTP, TCP, and UDP servers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before install any packages we need to ensure that our local package lists is up-to-date to update all installed packages run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmkgpxm6ri8vjk3fgifwg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmkgpxm6ri8vjk3fgifwg.png" alt="Alt Text" width="800" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To install Nginx we server packages run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;nginx

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkie80wjli1qnlthnyhk3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkie80wjli1qnlthnyhk3.png" alt="Alt Text" width="800" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After successfully installed Nginx we should enable it at boot time (load at startup) so we are running the following commands one by one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="c"&gt;#Enable Nginx&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;nginx

&lt;span class="c"&gt;#Start Nginx&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;nginx

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make sure everything is fine and  the status of Nginx web server on our Linux Ubuntu 18.4 we are running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status nginx


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fovekfxschmd16wxmqykn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fovekfxschmd16wxmqykn.png" alt="Alt Text" width="800" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To exit the status and return to home press (Ctrl + C) &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To make sure Nging is working open a web browser type the IP of Virtual Machine then hit the enter you will see the result of your goal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2zd90quyxyef3msk8qb3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2zd90quyxyef3msk8qb3.png" alt="Alt Text" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5 : Deploying ASP.NET Core App
&lt;/h2&gt;

&lt;p&gt;Simple asp.net core mvc app has created before, so we are going to deploying it to Nginx web root default directory on Virtual Machine.&lt;br&gt;
Run the following command to create a new directory is called ( simpleapponlinux ) in Nginx web root /var/www&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo mkdir&lt;/span&gt; /var/www/simpleapponlinux

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We run the following command in Package Manager Console inside Visual Studio 2019 to publish the app and its dependencies to a directory then deploy all compiled files to host system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
 dotnet publish &lt;span class="nt"&gt;-c&lt;/span&gt; release


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy32gvowjlckfzkwjbzoi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy32gvowjlckfzkwjbzoi.png" alt="Alt Text" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to use FileZilla as SFTP server to deploy the app on my local machine to /var/www/simpleapponlinux on Ubuntu Virtual Machine.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw013ufmr0d36jy8cyhiu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw013ufmr0d36jy8cyhiu.png" alt="Alt Text" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;May we are getting this error during transferring app files&lt;br&gt;
Tip: Error: /var/www/simpleapponlinux/YourAppOnLinux.dll: open for write permission denied Error: File transfer failed&lt;br&gt;
to fixed that we are going to running  the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; rebin /var/www/simpleapponlinux

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;sudo chown -R used to change the ownership of files or directories to rebin user.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After we have given the permission and uploaded entire our app content to /var/www/simpleapponlinux directory we need to run the app to ensure that is working well and getting some information like localhost url and its ports that is required in the next step.&lt;br&gt;
To do that we are running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; /var/www/simpleapponlinux

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we should be here ( /var/www/simpleapponlinux$ ) and we running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
/var/www/simpleapponlinux&lt;span class="nv"&gt;$ &lt;/span&gt;dotnet YourAppOnLinux.dll

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd15mjfpq39fw46wag942.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd15mjfpq39fw46wag942.png" alt="Alt Text" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6 : Create Server Block
&lt;/h2&gt;

&lt;p&gt;Ngnix server block allows us to run or host multiple websites on a single virtual Machine, so in this step we need to create our server block in order to forward all requests to our app&lt;br&gt;
I use nano simple text editor to modify the Nginx default server block in /etc/nginx/sites-available we are running the following command to modify the default Ngnix server block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/nginx/sites-available/default

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5r3q7e7ks32dt3vz8s0r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5r3q7e7ks32dt3vz8s0r.png" alt="Alt Text" width="800" height="741"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mark the text you want to cut press (Ctrl + ^).&lt;/li&gt;
&lt;li&gt;Use the arrow keys to select the text you want to cut.&lt;/li&gt;
&lt;li&gt;Cut the selected the text press (Ctrl + K)&lt;/li&gt;
&lt;li&gt;Right click and paste the following simple server block
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
server &lt;span class="o"&gt;{&lt;/span&gt;
    listen 80&lt;span class="p"&gt;;&lt;/span&gt;
    location / &lt;span class="o"&gt;{&lt;/span&gt;
  proxy_pass http://localhost:5000&lt;span class="p"&gt;;&lt;/span&gt;
  proxy_http_version 1.1&lt;span class="p"&gt;;&lt;/span&gt;
  proxy_set_header Upgrade &lt;span class="nv"&gt;$http_upgrade&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  proxy_set_header Connection keep-alive&lt;span class="p"&gt;;&lt;/span&gt;
  proxy_set_header Host &lt;span class="nv"&gt;$http_host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  proxy_cache_bypass &lt;span class="nv"&gt;$http_upgrade&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Save the modified default file press (Ctrl + O) and hit the enter&lt;/li&gt;
&lt;li&gt;To exit the nano editor press (Ctrl + x) it will ask you to exit write Y and hit the enter on your keyboard.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We have replaced content of the default server block file on Nginx so we need to reload changes that we have made before we running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;nginx &lt;span class="nt"&gt;-s&lt;/span&gt; reload


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 7 : Creating Service Unit File
&lt;/h2&gt;

&lt;p&gt;In this step we are going to create a custom service unit file so&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The service unit files define processes that are managed by systemd or contains information about a process which is managed by systemd to start or stop the service. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To keep running our app in the background as unite service we will take advantage of that file, so we need to create a. service file in the systemd directory and run the following command for that purpose.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/systemd/system/appserviceunitefile.service

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running that command, the nano simple text editor will be open immediately just copy the following configuration and past it into the nano text editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Unit]
&lt;span class="nv"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Asp.NET Web App now is running on Ubuntu

&lt;span class="o"&gt;[&lt;/span&gt;Service]
&lt;span class="nv"&gt;WorkingDirectory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/var/www/simpleapponlinux
&lt;span class="nv"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/bin/dotnet /var/www/simpleapponlinux/YourAppOnLinux.dll
&lt;span class="nv"&gt;Restart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;always
&lt;span class="c"&gt;# Restart service after 10 seconds if the dotnet service crashes:&lt;/span&gt;
&lt;span class="nv"&gt;RestartSec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10
&lt;span class="nv"&gt;KillSignal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;SIGINT
&lt;span class="nv"&gt;SyslogIdentifier&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;myapponlinux-log
&lt;span class="nv"&gt;User&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rebin
&lt;span class="nv"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;ASPNETCORE_ENVIRONMENT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Production
&lt;span class="nv"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;DOTNET_PRINT_TELEMETRY_MESSAGE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;Install]
&lt;span class="nv"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;multi-user.target

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it is time to save the modified. service file press (Ctrl + O) and hit the enter, to exit the nano editor press (Ctrl + x).&lt;/p&gt;

&lt;p&gt;To enable and register (appserviceunitefile.service) unite file service at a boot we should running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;appserviceunitefile.service

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we should see the following message to ensure the our unite file of service has been created successfully.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
Created symlink /etc/systemd/system/multi-user.target.wants/appserviceunitefile.service →
/etc/systemd/system/appserviceunitefile.service.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the following command to perform and start the unite of service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start appserviceunitefile.service

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last command we want to use is to check the status of the ( appserviceunitefile.service ) to ensure the service is active or not run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status appserviceunitefile.service

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5ivkalg371fux4fn3p8e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5ivkalg371fux4fn3p8e.png" alt="Alt Text" width="800" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make sure the Asp.net Core MVC app is working open a web browser and type the IP of Virtual Machine and hit the enter you will see that Asp.Net Core is working on Linux very well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3kfwzp8c1uohjzlitckr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3kfwzp8c1uohjzlitckr.png" alt="Alt Text" width="800" height="542"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Congratulations 🎉
&lt;/h3&gt;

&lt;p&gt;You have successfully run an Asp.Net Core App on Linux (Ubuntu 18.04 LTS)&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial you have learned how to deploy an ASP.NET Core MVC App as well as install Nginx web server on Linux Ubuntu 18.04 LTS Azure virtual machine.&lt;/p&gt;

&lt;p&gt;ASP.NET Core is an open source, cross platform and high-performance web framework to build the modern web applications.&lt;/p&gt;

&lt;p&gt;Nginx is a powerful web server open source, which can also be used as a reverse proxy or load balancing.&lt;/p&gt;

&lt;p&gt;The source code of the app used as a demo can be found &lt;a href="https://github.com/4Rebin/Asp.netCoreAppDemo" rel="noopener noreferrer"&gt;this link&lt;/a&gt; on GitHub.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>linux</category>
      <category>azure</category>
      <category>aspnet</category>
    </item>
  </channel>
</rss>
