<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>nginx &amp;mdash; Simple Engineering</title>
    <link>https://getsimple.works/tag:nginx</link>
    <description></description>
    <pubDate>Wed, 13 May 2026 21:18:56 +0000</pubDate>
    <item>
      <title>Easy nodejs deployment</title>
      <link>https://getsimple.works/easy-nodejs-deployment?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[This article is going to explore how to deploy a nodejs application on a traditional linux server -- in a non-cloud environment. Even though the use case is Ubuntu, any Linux distro or mac would work perfectly fine. &#xA;&#xA;  For information on deploying on non-traditional servers, read: &#34;Deploying nodejs applications&#34;. For zero-downtime knowledge, read  &#34;How to achieve zero downtime deployment with nodejs&#34; &#xA;&#xA;In this article we will talk about: &#xA;&#xA;Preparing nodejs deployable releases &#xA;Configuring nodejs deployment environment &#xA;Deploying nodejs application on bare metal Ubuntu server &#xA;Switching on nodejs application to be available to the world ~ adding nginx for the reverse proxy to make the application available to the world&#xA;post-deployment support -- production support &#xA;&#xA;  Even though this blog post was designed to offer complementary materials to those who bought my Testing nodejs Applications book book, the content can help any software developer to level up their knowledge. You may use this link to buy the book.  Testing nodejs Applications Book Cover&#xA;&#xA;Preparing a deployable release&#xA;&#xA;There are several angles to look at release and deployment from. There are also several ways to release nodejs code, npm and tar for instance, and that depending on the environment in which the code is designed to run. Amongst environments, server-side, universal, or command line are classic examples.&#xA;&#xA;In addition, we have to take a look from a dependency management perspective. Managing dependencies at deployment time has two vectors to take into account: whether the deployment happens on online or offline. &#xA;&#xA;  For the code to be prepared for release, it has to be packaged. Two methods of packaging nodejs software, amongst other things, are managed packaging and bundling. More on this is discussed here&#xA;&#xA;As a plus, versioning should be taken into consideration when preparing a deployable release. The versioning that is a little common circulation is SemVer. &#xA;&#xA;Configuring deployment environment &#xA;&#xA;Before we dive into deployment challenges, let&#39;s look at key software and configuration requirements. &#xA;&#xA;As usual, first-time work can be hard to do. But the yield should be then predictable, flexible to improvement, and capable of being built-upon for future deployments. For context, the deployment environment we are talking about in this section is the production environment.  &#xA;&#xA;Two key configurations are an nginx reverse proxy server and nodejs. But, &#34;Why coupling nodejs server to an nginx reverse proxy server&#34;? The answer to this question is two folds. First, both nodejs and nginx are single-threaded non-blocking reactive systems. Second, the wide adoption of these two tools by the developer community makes it an easy choice, from both influence and availability of collective knowledge the developer community shares via forums/blogs and popular QA sites. &#xA;&#xA;  How to install nginx server ~ there is an article dedicated to this. How to configure nginx as a nodejs application proxy server ~ there is an article dedicated to this. &#xA;&#xA;Additional tools to install and configure may include: mongod database server, redis server, monit for monitoring, upstart for enhancing the init system.&#xA;&#xA;There is a need to better understand the tools required to run nodejs application. It is also our responsibility as developers to have a basic understanding of each tool and the roles it plays in our project, in order to figure out how to configure each tool.&#xA;&#xA;Download source code&#xA;&#xA;Starting from the utility perspective, there is quite a collection of tools that are required to run on the server, alongside our nodejs application. Such software needs to be installed, and updated ~ for patch releases, and upgraded ~ to new major versions to keep the system secure and capable(bug-free/enhanced with new features).&#xA;&#xA;From the packaging perspective, both supporting tools and nodejs applications adhere to a packaging strategy that makes it easy to deploy. When packaging is indeed a bundle, wget/curl can be used to download binaries. When dealing with discoverable packages, npm/yarn/brew can also be used to download our application and its dependencies. Both operation yield same outcomes, which is un-packaging, configuration and installation.&#xA;&#xA;To deploy versioned nodejs application on bare metal Ubuntu server  ~ understanding file system tweaks such as symlink-ing for faster deployments can save time for future deployments.&#xA;&#xA;first time on server side  &#xA;$ apt-get update&#xA;$ apt-get install git&#xA;&#xA;updating|upgrading server side code&#xA;$ apt-get update&#xA;$ apt-get upgrade&#xA;$ brew upgrade &#xA;$ npm upgrade &#xA;&#xA;Package download and installs &#xA;$ /bin/bash -c &#34;$(curl -fsSL https://url.tld/version/install.sh)&#34;&#xA;$ wget -O - https://url.tld/version/install.sh | bash&#xA;&#xA;Discoverable packages &#xA;$ npm install application@next &#xA;$ yarn add application@next &#xA;$ brew install application&#xA;Example: &#xA;&#xA;  The command above can be automated via a scheduled task. Both npm and yarn support the installation of applications bundled in a .tar file. See an example of a simple script source. We have to be mindful to clean up download directories, to save disk space. &#xA;&#xA;Switching on the application &#xA;&#xA;It sounds repetitive, but running npm start does not guarantee the application to be visible outside the metal server box the application is hosted on. This magic belongs to the nginx reverse proxy we were referring to in earlier paragraphs. &#xA;&#xA;A typical nodejs application needs to start one or more of the following services, each time to reboot the application. &#xA;&#xA;symlinking new version to default application path&#xA;$ ln -sfn /var/www/new/version/appname /var/www/appname &#xA;&#xA;$ service nginx restart #nginx|apache server&#xA;$ service redis restart #redis server&#xA;$ service restart mongod #database server in some cases&#xA;$ service appname restart #application itself&#xA;Example:&#xA;&#xA;  PS: Above services are managed with uptime&#xA;&#xA;Adding nginx reverse proxy makes the application available to the outside world. Switching on/off the application can be summarized in one command: service nginx stop. Likewise, to switch off and back on can be issued in one command: service nginx restart.&#xA;&#xA;Post-deployment support &#xA;&#xA;Asynchronous timely tasks can be used to resolve a wide range of issues. Background tasks such as fetching updates from third-party data providers, system health check, and notifications, automated software updates, database cleaning, cache busting, scheduled expensive/CPU intensive batch processing jobs just to name a few. &#xA;&#xA;It is possible to leverage existing asynchronous timely OS-provided tasks processing infrastructure to achieve any of the named use cases, as it is true for third-party tools to do exactly the same job. &#xA;&#xA;Rule of thumb&#xA;&#xA;The following is a mental model that can be applied to the common use cases of releases. It may be basic for DevOps professionals, but useful enough for developers doing some operations work as well. &#xA;&#xA;Prepare deployable releases&#xA;Update and install binaries ~ using apt, brew etc.  &#xA;Download binaries ~ using git,wget, curl or brew&#xA;symlink directories(/log, /config, /app)&#xA;Restart  servers and services ~ redis, nginx, mongodb and app &#xA;When something goes bad ~ walk two steps back. That is our rollback strategy.  &#xA;&#xA;  This model can be refined, to make most of these tasks repeatable and automated, deployments included. &#xA;&#xA;Conclusion &#xA;&#xA;In this article, we revisited quick easy, and most basic nodejs deployment strategies. We also revisited how to expose the deployed applications to the world using nginx as a reverse proxy server. There are additional complimentary materials in the &#34;Testing nodejs applications&#34; book. &#xA;&#xA;References&#xA;&#xA;Testing nodejs Applications book&#xA;How to set up CI/CD Pipeline for a nodejs app with Jenkins ~ Moshe Ezderman - Medium&#xA;&#34;Build your dependencies into your deployable packages&#34;&#xA;&#xA;#snippets #code #annotations #question #discuss]]&gt;</description>
      <content:encoded><![CDATA[<p>This article is going to explore how to deploy a <code>nodejs</code> application on a traditional <code>linux</code> server — in a non-cloud environment. Even though the use case is Ubuntu, any Linux <em>distro</em> or <code>mac</code> would work perfectly fine.</p>

<blockquote><p>For information on deploying on non-traditional servers, read: <strong><em><a href="./deploying-nodejs-application">“Deploying <code>nodejs</code> applications”</a></em></strong>. For zero-downtime knowledge, read  <strong><em><a href="./achieving-nodejs-zero-downtime">“How to achieve zero downtime deployment with <code>nodejs</code>“</a></em></strong></p></blockquote>

<p><strong><em>In this article we will talk about:</em></strong></p>
<ul><li>Preparing <code>nodejs</code> deployable releases</li>
<li>Configuring <code>nodejs</code> deployment environment</li>
<li>Deploying <code>nodejs</code> application on bare metal Ubuntu server</li>
<li>Switching on <code>nodejs</code> application to be available to the world ~ adding <code>nginx</code> for the reverse proxy to make the application available to the world</li>
<li>post-deployment support — production support</li></ul>

<blockquote><p>Even though this blog post was designed to offer complementary materials to those who bought my <strong><em><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></em></strong> book, the content can help any software developer to level up their knowledge. <strong><em><a href="https://bit.ly/2ZFJytb">You may use this link to buy the book</a></em></strong>.  <a href="https://bit.ly/2ZFJytb"><img src="https://snap.as/a/42OS2vs.png" alt="Testing nodejs Applications Book Cover"/></a></p></blockquote>

<h2 id="preparing-a-deployable-release" id="preparing-a-deployable-release">Preparing a deployable release</h2>

<p>There are several angles to look at release and deployment from. There are also several ways to release <code>nodejs</code> code, <code>npm</code> and <code>tar</code> for instance, and that depending on the environment in which the code is designed to run. Amongst environments, server-side, universal, or command line are classic examples.</p>

<p>In addition, we have to take a look from a dependency management perspective. Managing dependencies at deployment time has two vectors to take into account: whether the deployment happens on <strong><em>online</em></strong> or <strong><em>offline</em></strong>.</p>

<blockquote><p>For the code to be prepared for release, it has to be packaged. Two methods of packaging <code>nodejs</code> software, amongst other things, are managed packaging and bundling. <a href="./deploying-nodejs-applications#reducing-friction">More on this is discussed here</a></p></blockquote>

<p>As a plus, versioning should be taken into consideration when preparing a deployable release. The versioning that is a little common circulation is <strong><em>SemVer</em></strong>.</p>

<h2 id="configuring-deployment-environment" id="configuring-deployment-environment">Configuring deployment environment</h2>

<p>Before we dive into deployment challenges, let&#39;s look at key software and configuration requirements.</p>

<p>As usual, first-time work can be hard to do. But the yield should be then predictable, flexible to improvement, and capable of being built-upon for future deployments. For context, the deployment environment we are talking about in this section is the production environment.</p>

<p>Two key configurations are an <code>nginx</code> reverse proxy server and <code>nodejs</code>. But, <em>“Why coupling <code>nodejs</code> server to an <code>nginx</code> reverse proxy server”</em>? The answer to this question is two folds. First, both <code>nodejs</code> and <code>nginx</code> are single-threaded non-blocking reactive systems. Second, the wide adoption of these two tools by the developer community makes it an easy choice, from both influence and availability of collective knowledge the developer community shares via forums/blogs and popular QA sites.</p>

<blockquote><p>How to install <code>nginx</code> server ~ [there is an article dedicated to this](). How to configure <code>nginx</code> as a <code>nodejs</code> application proxy server ~ <a href="./how-to-configure-nodejs-applications#configure-nginx-to-serve-nodejs-application">there is an article dedicated to this</a>.</p></blockquote>

<p>Additional tools to install and configure may include: <code>mongod</code> database server, <code>redis</code> server, <a href="https://mmonit.com/monit/#home"><code>monit</code></a> for monitoring, <a href="http://upstart.ubuntu.com/download.html"><code>upstart</code></a> for enhancing the <code>init</code> system.</p>

<p>There is a need to better understand the tools required to run <code>nodejs</code> application. It is also our responsibility as developers to have a basic understanding of each tool and the roles it plays in our project, in order to figure out how to configure each tool.</p>

<h2 id="download-source-code" id="download-source-code">Download source code</h2>

<p>Starting from the utility perspective, there is quite a collection of tools that are required to run on the server, alongside our <code>nodejs</code> application. Such software needs to be installed, and updated ~ for patch releases, and upgraded ~ to new major versions to keep the system secure and capable(bug-free/enhanced with new features).</p>

<p>From the packaging perspective, both supporting tools and <code>nodejs</code> applications adhere to a packaging strategy that makes it easy to deploy. When packaging is indeed a bundle, <code>wget</code>/<code>curl</code> can be used to download binaries. When dealing with discoverable packages, <code>npm</code>/<code>yarn</code>/<code>brew</code> can also be used to download our application and its dependencies. Both operation yield same outcomes, which is un-packaging, configuration and installation.</p>

<p>To deploy versioned <code>nodejs</code> application on bare metal Ubuntu server  ~ understanding file system tweaks such as symlink-ing for faster deployments can save time for future deployments.</p>

<pre><code class="language-shell">#first time on server side  
$ apt-get update
$ apt-get install git

#updating|upgrading server side code
$ apt-get update
$ apt-get upgrade
$ brew upgrade 
$ npm upgrade 

# Package download and installs 
$ /bin/bash -c &#34;$(curl -fsSL https://url.tld/version/install.sh)&#34;
$ wget -O - https://url.tld/version/install.sh | bash

# Discoverable packages 
$ npm install application@next 
$ yarn add application@next 
$ brew install application
</code></pre>

<p>_<em>Example</em>: _</p>

<blockquote><p>The command above can be automated via a scheduled task. Both <code>npm</code> and <code>yarn</code> support the installation of applications bundled in a <code>.tar</code> file. See an example of a simple script <a href="https://serverfault.com/a/226389">source</a>. We have to be mindful to clean up download directories, to save disk space.</p></blockquote>

<h2 id="switching-on-the-application" id="switching-on-the-application">Switching on the application</h2>

<p>It sounds repetitive, but running <code>npm start</code> does not guarantee the application to be visible outside the metal server box the application is hosted on. This magic belongs to the <code>nginx</code> reverse proxy we were referring to in earlier paragraphs.</p>

<p>A typical <code>nodejs</code> application needs to start one or more of the following services, each time to reboot the application.</p>

<pre><code class="language-shell"># symlinking new version to default application path
$ ln -sfn /var/www/new/version/appname /var/www/appname 

$ service nginx restart #nginx|apache server
$ service redis restart #redis server
$ service restart mongod #database server in some cases
$ service appname restart #application itself
</code></pre>

<p><em><em>Example</em>:</em></p>

<blockquote><p>PS: Above services are managed with <code>uptime</code></p></blockquote>

<p>Adding <code>nginx</code> reverse proxy makes the application available to the outside world. Switching on/off the application can be summarized in one command: <code>service nginx stop</code>. Likewise, to switch off and back on can be issued in one command: <code>service nginx restart</code>.</p>

<h2 id="post-deployment-support" id="post-deployment-support">Post-deployment support</h2>

<p>Asynchronous timely tasks can be used to resolve a wide range of issues. Background tasks such as <em>fetching updates from third-party data providers</em>, <em>system health check, and notifications</em>, <em>automated software updates</em>, <em>database cleaning</em>, <em>cache busting</em>, <em>scheduled expensive/CPU intensive batch processing jobs</em> just to name a few.</p>

<p>It is possible to leverage existing asynchronous timely OS-provided tasks processing infrastructure to achieve any of the named use cases, as it is true for third-party tools to do exactly the same job.</p>

<h2 id="rule-of-thumb" id="rule-of-thumb">Rule of thumb</h2>

<p>The following is a mental model that can be applied to the common use cases of releases. It may be basic for DevOps professionals, but useful enough for developers doing some operations work as well.</p>
<ul><li>Prepare deployable releases</li>
<li>Update and install binaries ~ using <code>apt</code>, <code>brew</code> etc.<br/></li>
<li>Download binaries ~ using <code>git</code>,<code>wget</code>, <code>curl</code> or <code>brew</code></li>
<li><code>symlink</code> directories(<code>/log</code>, <code>/config</code>, <code>/app</code>)</li>
<li>Restart  servers and services ~ <code>redis</code>, <code>nginx</code>, <code>mongodb</code> and <code>app</code></li>
<li>When something goes bad ~ walk two steps back. That is our rollback strategy.<br/></li></ul>

<blockquote><p>This model can be refined, to make most of these tasks repeatable and automated, deployments included.</p></blockquote>

<h2 id="conclusion" id="conclusion">Conclusion</h2>

<p>In this article, we revisited quick easy, and most basic <code>nodejs</code> deployment strategies. We also revisited how to expose the deployed applications to the world using <code>nginx</code> as a reverse proxy server. There are additional complimentary materials in the <strong>“Testing <code>nodejs</code> applications”</strong> book.</p>

<h2 id="references" id="references">References</h2>
<ul><li><a href="https://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></li>
<li>How to set up CI/CD Pipeline for a <code>nodejs</code> app with Jenkins ~ <a href="https://medium.com/@mosheezderman/how-to-set-up-ci-cd-pipeline-for-a-node-js-app-with-jenkins-c51581cc783c">Moshe Ezderman – Medium</a></li>
<li><a href="https://strongloop.com/strongblog/node-js-deploy-production-best-practice/"><em>“Build your dependencies into your deployable packages”</em></a></li></ul>

<p><a href="https://getsimple.works/tag:snippets" class="hashtag"><span>#</span><span class="p-category">snippets</span></a> <a href="https://getsimple.works/tag:code" class="hashtag"><span>#</span><span class="p-category">code</span></a> <a href="https://getsimple.works/tag:annotations" class="hashtag"><span>#</span><span class="p-category">annotations</span></a> <a href="https://getsimple.works/tag:question" class="hashtag"><span>#</span><span class="p-category">question</span></a> <a href="https://getsimple.works/tag:discuss" class="hashtag"><span>#</span><span class="p-category">discuss</span></a></p>
]]></content:encoded>
      <guid>https://getsimple.works/easy-nodejs-deployment</guid>
      <pubDate>Thu, 17 Jun 2021 05:08:19 +0000</pubDate>
    </item>
    <item>
      <title>How to install upstart</title>
      <link>https://getsimple.works/how-to-install-upstart?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[This article revisits essentials on how to install upstart an event based daemon for starting/stopping tasks on development and production servers.&#xA;&#xA;  This article has complementary materials to the Testing nodejs Applications book. However, the article is designed to help both those who already bought the book, as well as the wide audience of software developers  to setup working environment.  Testing Nodejs Applications Book Cover&#xA;You can grab a copy of this book on this link&#xA;&#xA;There are a plethora of task execution solutions, for instance systemd and init, rather complex to work with. That makes upstart a good alternative to such tools. &#xA;&#xA;In this article you will learn about:&#xA;&#xA;-- &#xA;&#xA;Tools available for task execution &#xA;How to install upstart task execution&#xA;How to write basic upstart task  &#xA;&#xA;Installing upstart on Linux &#xA;&#xA;It is always a good idea to update the system before start working. There is no exception, even when a daily task updates automatically binaries. That can be achieved on Ubuntu and Aptitude enabled systems as following:&#xA;&#xA;$ apt-get update # Fetch list of available updates&#xA;$ apt-get upgrade # Upgrades current packages&#xA;$ apt-get dist-upgrade # Installs only new updates&#xA;Example: updating aptitude binaries&#xA;&#xA;At this point most of packages should be installed or upgraded. Except Packages whose PPA have been removed or not available in the registry. Installing software can be done by installing binaries, or using Ubuntu package manager.&#xA;&#xA;Installing a upstart on Linux using apt&#xA;&#xA;Installing upstart on macOS &#xA; &#xA;upstart is a utility designed mainly for Linux systems. However, macOS has its equivalent, launchctl designed to stop/stop processes prior/after the system restarts.   &#xA;&#xA;Installing upstart on a Windows machine&#xA;&#xA;Whereas macOS  systems and Linux are quite relax when it comes to working with system processes, Windows is a beast on its own way. upstart was built for nix systems but  there is no equivalent on Windows systems: Service Control Manager. It basically has the same ability to check and restart processes that are failing. &#xA;&#xA;Automated upgrades &#xA;&#xA;Before we dive into automatic upgrades, we should consider nuances associated to managing a mongodb instance. The updates fall into two major, quite interesting, categories: patch updates and version upgrades. &#xA;&#xA;Following the SemVer ~ aka Semantic Versioning standard, it is recommended that the only pair minor versions be considered for version upgrades. This is because minor versions, as well as major versions, are subject to introducing breaking changes or incompatibility between two versions.  On the other hand, patches do not introduce breaking changes. Those can therefore be automated. &#xA;&#xA;In case of a critical infrastructure piece of processes state management calibre, we expect breaking changes when a new version introduces a configuration setting is added, or dropped between two successive versions. Upstart provides backward compatibility, so chances for breaking changes between two minor versions is really minimal.  &#xA;&#xA;  We should highlight that it is always better to upgrade at deployment time. The process is even easier in containerized context. We should also automate only patches, to avoid to miss security patches. &#xA;&#xA;In the context of Linux, we will use the unattended-upgrades package to do the work. &#xA;&#xA;$ apt-get install unattended-upgrades apticron&#xA;Example: install unattended-upgrades&#xA;&#xA;Two things to fine-tune to make this solution work are: to enable a blacklist of packages we do not to automatically update, and two, to enable particular packages we would love to update on a periodical basis. That is compiled in the following shell scripts.&#xA;&#xA;Unattended-Upgrade::Allowed-Origins {&#xA;//  &#34;${distroid}:${distrocodename}&#34;;&#xA;    &#34;${distroid}:${distrocodename}-security&#34;; # upgrading security patches only &#xA;//   &#34;${distroid}:${distrocodename}-updates&#34;;  &#xA;//  &#34;${distroid}:${distrocodename}-proposed&#34;;&#xA;//  &#34;${distroid}:${distrocodename}-backports&#34;;&#xA;};&#xA;&#xA;Unattended-Upgrade::Package-Blacklist {&#xA;    &#34;vim&#34;;&#xA;};&#xA;Example: fine-tune the blacklist and whitelist in /etc/apt/apt.conf.d/50unattended-upgrades&#xA;&#xA;The next step is necessary to make sure  unattended-upgrades download, install and cleanups tasks have a default period: once, twice a day or a week. &#xA;&#xA;APT::Periodic::Update-Package-Lists &#34;1&#34;;            # Updates package list once a day&#xA;APT::Periodic::Download-Upgradeable-Packages &#34;1&#34;;   # download upgrade candidates once a day&#xA;APT::Periodic::AutocleanInterval &#34;7&#34;;               # clean week worth of unused packages once a week&#xA;APT::Periodic::Unattended-Upgrade &#34;1&#34;;              # install downloaded packages once a day&#xA;Example: tuning the tasks parameter /etc/apt/apt.conf.d/20auto-upgrades&#xA;&#xA;This approach works on Linux(Ubuntu), especially deployed in production, but not Windows nor macOS. The last issue, is to be able to report problems when an update fails, so that a human can intervene whenever possible. That is where the second tool apticron in first paragraph intervenes. To make it work, we will specify which email to send messages to, and that will be all. &#xA;&#xA;EMAIL=&#34;email@host.tld&#34;&#xA;Example: tuning reporting tasks email parameter /etc/apticron/apticron.conf&#xA;&#xA;Conclusion&#xA;&#xA;In this article we revisited ways to install upstart on various platforms. Even though configuration was beyond the scope of this article*, we managed to get everyday quick refreshers out.&#xA;&#xA;References&#xA;&#xA; An A-Z Index of the Apple macOS command line (macOS bash) and the Apple macOS How-to guides and examples&#xA; Configuring nodejs applications&#xA;&#xA;#nodejs #homebrew #UnattendedUpgrades #nginx #y2020 #Jan2020 #HowTo #ConfiguringNodejsApplications #tdd #TestingNodejsApplications]]&gt;</description>
      <content:encoded><![CDATA[<p>This article revisits essentials on how to install <code>upstart</code> an event based daemon for starting/stopping tasks on development and production servers.</p>

<blockquote><p>This article has complementary materials to the <strong><em><a href="http://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></em></strong>. However, the article is designed to help both those who already bought the book, as well as the wide audience of software developers  to setup working environment.  <a href="http://bit.ly/2ZFJytb"><img src="https://snap.as/a/42OS2vs.png" alt="Testing Nodejs Applications Book Cover"/></a>
<strong><em><a href="http://bit.ly/2ZFJytb">You can grab a copy of this book on this link</a></em></strong></p></blockquote>

<p>There are a plethora of task execution solutions, for instance <code>systemd</code> and <code>init</code>, rather complex to work with. That makes upstart a good alternative to such tools.</p>

<p><strong>In this article you will learn about:</strong></p>

<p><strong>—</strong></p>
<ul><li>Tools available for task execution</li>
<li>How to install <code>upstart</code> task execution</li>
<li>How to write basic <code>upstart</code> task<br/></li></ul>

<h2 id="installing-upstart-on-linux" id="installing-upstart-on-linux">Installing <code>upstart</code> on Linux</h2>

<p>It is always a good idea to update the system before start working. There is no exception, even when a daily task updates automatically binaries. That can be achieved on Ubuntu and Aptitude enabled systems as following:</p>

<pre><code class="language-shell">$ apt-get update # Fetch list of available updates
$ apt-get upgrade # Upgrades current packages
$ apt-get dist-upgrade # Installs only new updates
</code></pre>

<p><em><em>Example</em>: updating aptitude binaries</em></p>

<p>At this point most of packages should be installed or upgraded. Except Packages whose PPA have been removed or not available in the registry. Installing software can be done by installing binaries, or using Ubuntu package manager.</p>

<h3 id="installing-a-upstart-on-linux-using-apt" id="installing-a-upstart-on-linux-using-apt">Installing a <code>upstart</code> on Linux using <code>apt</code></h3>

<h2 id="installing-upstart-on-macos" id="installing-upstart-on-macos">Installing <code>upstart</code> on macOS</h2>

<p><code>upstart</code> is a utility designed mainly for Linux systems. However, macOS has its equivalent, <code>launchctl</code> designed to stop/stop processes prior/after the system restarts.</p>

<h2 id="installing-upstart-on-a-windows-machine" id="installing-upstart-on-a-windows-machine">Installing <code>upstart</code> on a Windows machine</h2>

<p>Whereas macOS  systems and Linux are quite relax when it comes to working with system processes, Windows is a beast on its own way. <code>upstart</code> was built for <code>*nix</code> systems but  there is no equivalent on Windows systems: Service Control Manager. It basically has the same ability to check and restart processes that are failing.</p>

<h2 id="automated-upgrades" id="automated-upgrades">Automated upgrades</h2>

<p>Before we dive into automatic upgrades, we should consider nuances associated to managing a <code>mongodb</code> instance. The updates fall into two major, quite interesting, categories: <strong><em>patch</em></strong> updates and <strong><em>version upgrades</em></strong>.</p>

<p>Following the <a href="https://semver.org/">SemVer ~ <em>aka Semantic Versioning</em></a> standard, it is recommended that the only pair <strong><em>minor</em></strong> versions be considered for version upgrades. This is because minor versions, as well as major versions, are subject to introducing breaking changes or incompatibility between two versions.  On the other hand, patches do not introduce breaking changes. Those can therefore be automated.</p>

<p>In case of a critical infrastructure piece of processes state management calibre, we expect breaking changes when a new version introduces a configuration setting is added, or dropped between two successive versions. Upstart provides backward compatibility, so chances for breaking changes between two minor versions is really minimal.</p>

<blockquote><p>We should highlight that it is always better to upgrade at deployment time. The process is even easier in containerized context. We should also automate only patches, to avoid to miss security patches.</p></blockquote>

<p>In the context of Linux, we will use the <strong><em>unattended-upgrades</em></strong> package to do the work.</p>

<pre><code class="language-shell">$ apt-get install unattended-upgrades apticron
</code></pre>

<p><em><em>Example</em>: install unattended-upgrades</em></p>

<p>Two things to fine-tune to make this solution work are: to enable a blacklist of packages we do not to automatically update, and two, to enable particular packages we would love to update on a periodical basis. That is compiled in the following shell scripts.</p>

<pre><code class="language-shell">Unattended-Upgrade::Allowed-Origins {
//  &#34;${distro_id}:${distro_codename}&#34;;
    &#34;${distro_id}:${distro_codename}-security&#34;; # upgrading security patches only 
//   &#34;${distro_id}:${distro_codename}-updates&#34;;  
//  &#34;${distro_id}:${distro_codename}-proposed&#34;;
//  &#34;${distro_id}:${distro_codename}-backports&#34;;
};

Unattended-Upgrade::Package-Blacklist {
    &#34;vim&#34;;
};
</code></pre>

<p><em><em>Example</em>: fine-tune the blacklist and whitelist in <code>/etc/apt/apt.conf.d/50unattended-upgrades</code></em></p>

<p>The next step is necessary to make sure  <strong><em>unattended-upgrades</em></strong> download, install and cleanups tasks have a default period: once, twice a day or a week.</p>

<pre><code class="language-shell">APT::Periodic::Update-Package-Lists &#34;1&#34;;            # Updates package list once a day
APT::Periodic::Download-Upgradeable-Packages &#34;1&#34;;   # download upgrade candidates once a day
APT::Periodic::AutocleanInterval &#34;7&#34;;               # clean week worth of unused packages once a week
APT::Periodic::Unattended-Upgrade &#34;1&#34;;              # install downloaded packages once a day
</code></pre>

<p><em><em>Example</em>: tuning the tasks parameter <code>/etc/apt/apt.conf.d/20auto-upgrades</code></em></p>

<p>This approach works on Linux(Ubuntu), especially deployed in production, but not Windows nor macOS. The last issue, is to be able to report problems when an update fails, so that a human can intervene whenever possible. That is where the second tool <code>apticron</code> in first paragraph intervenes. To make it work, we will specify which email to send messages to, and that will be all.</p>

<pre><code class="language-shell">EMAIL=&#34;&lt;email&gt;@&lt;host.tld&gt;&#34;
</code></pre>

<p><em><em>Example</em>: tuning reporting tasks email parameter <code>/etc/apticron/apticron.conf</code></em></p>

<h2 id="conclusion" id="conclusion">Conclusion</h2>

<p>In this article we revisited ways to install <code>upstart</code> on various platforms. Even though <strong><em><a href="https://getsimple.works/how-to-configure-nodejs-applications#configure-upstart-to-start-nodejs-application">configuration was beyond the scope of this article</a></em></strong>, we managed to get everyday quick refreshers out.</p>

<h2 id="references" id="references">References</h2>
<ul><li><em><a href="https://ss64.com/osx/">An A-Z Index of the Apple macOS command line (macOS bash)</a></em> and the <em><a href="https://ss64.com/osx/syntax.html">Apple macOS How-to guides and examples</a></em></li>
<li><a href="https://getsimple.works/how-to-configure-nodejs-applications">Configuring <code>nodejs</code> applications</a></li></ul>

<p><a href="https://getsimple.works/tag:nodejs" class="hashtag"><span>#</span><span class="p-category">nodejs</span></a> <a href="https://getsimple.works/tag:homebrew" class="hashtag"><span>#</span><span class="p-category">homebrew</span></a> <a href="https://getsimple.works/tag:UnattendedUpgrades" class="hashtag"><span>#</span><span class="p-category">UnattendedUpgrades</span></a> <a href="https://getsimple.works/tag:nginx" class="hashtag"><span>#</span><span class="p-category">nginx</span></a> <a href="https://getsimple.works/tag:y2020" class="hashtag"><span>#</span><span class="p-category">y2020</span></a> <a href="https://getsimple.works/tag:Jan2020" class="hashtag"><span>#</span><span class="p-category">Jan2020</span></a> <a href="https://getsimple.works/tag:HowTo" class="hashtag"><span>#</span><span class="p-category">HowTo</span></a> <a href="https://getsimple.works/tag:ConfiguringNodejsApplications" class="hashtag"><span>#</span><span class="p-category">ConfiguringNodejsApplications</span></a> <a href="https://getsimple.works/tag:tdd" class="hashtag"><span>#</span><span class="p-category">tdd</span></a> <a href="https://getsimple.works/tag:TestingNodejsApplications" class="hashtag"><span>#</span><span class="p-category">TestingNodejsApplications</span></a></p>
]]></content:encoded>
      <guid>https://getsimple.works/how-to-install-upstart</guid>
      <pubDate>Fri, 31 Jan 2020 22:51:29 +0000</pubDate>
    </item>
    <item>
      <title>How to install nginx</title>
      <link>https://getsimple.works/how-to-install-nginx?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[This article revisits essentials on how to install nginx non blocking single threaded multipurpose web server on development and production servers.&#xA;&#xA;  This article has complementary materials to the Testing nodejs Applications book. However, the article is designed to help both those who already bought the book, as well as the wide audience of software developers  to setup working environment.  Testing Nodejs Applications Book Cover&#xA;You can grab a copy of this book on this link  &#xA;&#xA;Installing nginx on Linux &#xA;&#xA;It is always a good idea to update the system before start working. There is no exception, even when a daily task updates automatically binaries. That can be achieved on Ubuntu and Aptitude enabled systems as following:&#xA;&#xA;$ apt-get update # Fetch list of available updates&#xA;$ apt-get upgrade # Upgrades current packages&#xA;$ apt-get dist-upgrade # Installs only new updates&#xA;Example: updating aptitude binaries&#xA;&#xA;At this point most of packages should be installed or upgraded. Except Packages whose PPA have been removed or not available in the registry. Installing software can be done by installing binaries, or using Ubuntu package manager.&#xA;&#xA;Installing a nginx on Linux using apt&#xA;&#xA;Updating/Upgrading or first install of &#xA;$ sudo add-apt-repository ppa:nginx/stable&#xA;$ sudo apt-get update &#xA;$ sudo apt-get install - nginx &#xA;&#xA;To restart the service:&#xA;$ sudo service nginx restart &#xA;Example: updating PPA and installing nginx binaries&#xA;&#xA;  Adding nginx PPA in first step is only required for first installs, on a system that does not have the PPA available in the system database.  &#xA;&#xA;Installing nginx on macOS &#xA;&#xA;In case homebrew is not already available on your mac, this is how to get one up and running. On its own, homebrew depends on ruby runtime to be available. &#xA;&#xA;  homebrew is a package manager and software installation tool that makes most developer tools installation a breeze. &#xA;&#xA;$ /usr/bin/ruby -e &#34;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&#34;&#xA;Example: installation instruction as provided by brew.sh&#xA;&#xA;Generally speaking, this is how to install/uninstall things with brew &#xA;&#xA;$ brew install wget &#xA;$ brew uninstall wget &#xA;Example: installing/uninstalling wget binaries using homebrew&#xA;&#xA;  We have to to stress on the fact that Homebrew installs packages to their own directory and then symlinks their files into /usr/local.&#xA;&#xA;It is always a good idea to update the system before start working. And that, even when we have a daily task that automatically updates the system for us. macOS  can use homebrew package manager on maintenance matters. To update/upgrade or check outdated packages, following commands would help. &#xA;&#xA;$ brew outdated                   # lists all outdated packages&#xA;$ brew cleanup -n                 # visualize the list of things are going to be cleaned up.&#xA;&#xA;$ brew upgrade                    # Upgrades all things on the system&#xA;$ brew update                     # Updates all outdated + brew itself&#xA;$ brew update formula           # Updates one formula&#xA;&#xA;$ brew install formula@version    # Installs formula at a particular version.&#xA;$ brew tap formular@version/brew  # Installs formular from third party repository&#xA;&#xA;untap/re-tap a repo when previous installation failed&#xA;$ brew untap formular &amp;&amp; brew tap formula   &#xA;$ brew services start formular@version&#xA;Example: key commands to work with homebrew cli&#xA;&#xA;  For more informations, visit: Homebrew ~ FAQ.&#xA;&#xA;Installing a nginx on a Mac using homebrew&#xA;&#xA;$ brew install nginx@1.17.8  # as in formula@version&#xA;Example: installing nginx using homebrew&#xA;&#xA;Installing nginx on a Windows machine&#xA;&#xA;MacOs comes with Python and Ruby already enabled, these two languages are somehow required to run successfully a nodejs environment on a Mac. This is an easy target as nginx gives windows binaries that we can download and install on a couple of clicks.&#xA;&#xA;Automated upgrades &#xA;&#xA;Before we dive into automatic upgrades, we should consider nuances associated to managing an nginx deployment. The updates fall into two major, quite interesting, categories: patch updates and version upgrades. &#xA;&#xA;Following the SemVer ~ aka Semantic Versioning standard, it is not recommended to consider minor/major versions for automated upgrades. One of the reasons being that these versions are subject to introducing breaking changes or incompatibility between two versions.  On the other hand, patches are less susceptible to introduce breaking changes, whence ideal candidates for automated upgrades. Another among other reasons, being that security fixes are released as patches to a minor version.  &#xA;&#xA;In case of a WebServer, breaking changes may be introduced when a critical configuration setting is added, or dropped between two successive versions. &#xA;&#xA;  We should highlight that it is always better to upgrade at deployment time. The process is even easier in containerized context. We should also automate only patches, to avoid to miss security patches. &#xA;&#xA;In the context of Linux, we will use the unattended-upgrades package to do the work. &#xA;&#xA;$ apt-get install unattended-upgrades apticron&#xA;Example: install unattended-upgrades&#xA;&#xA;Two things to fine-tune to make this solution work are: to enable a blacklist of packages we do not to automatically update, and two, to enable particular packages we would love to update on a periodical basis. That is compiled in the following shell scripts.&#xA;&#xA;Unattended-Upgrade::Allowed-Origins {&#xA;//  &#34;${distroid}:${distrocodename}&#34;;&#xA;    &#34;${distroid}:${distrocodename}-security&#34;; # upgrading security patches only &#xA;//   &#34;${distroid}:${distrocodename}-updates&#34;;  &#xA;//  &#34;${distroid}:${distrocodename}-proposed&#34;;&#xA;//  &#34;${distroid}:${distrocodename}-backports&#34;;&#xA;};&#xA;&#xA;Unattended-Upgrade::Package-Blacklist {&#xA;    &#34;vim&#34;;&#xA;};&#xA;Example: fine-tune the blacklist and whitelist in /etc/apt/apt.conf.d/50unattended-upgrades&#xA;&#xA;The next step is necessary to make sure  unattended-upgrades download, install and cleanups tasks have a default period: once, twice a day or a week. &#xA;&#xA;APT::Periodic::Update-Package-Lists &#34;1&#34;;            # Updates package list once a day&#xA;APT::Periodic::Download-Upgradeable-Packages &#34;1&#34;;   # download upgrade candidates once a day&#xA;APT::Periodic::AutocleanInterval &#34;7&#34;;               # clean week worth of unused packages once a week&#xA;APT::Periodic::Unattended-Upgrade &#34;1&#34;;              # install downloaded packages once a day&#xA;Example: tuning the tasks parameter /etc/apt/apt.conf.d/20auto-upgrades&#xA;&#xA;This approach works on Linux(Ubuntu), especially deployed in production, but not Windows nor macOS. The last issue, is to be able to report problems when an update fails, so that a human can intervene whenever possible. That is where the second tool apticron in first paragraph intervenes. To make it work, we will specify which email to send messages to, and that will be all. &#xA;&#xA;EMAIL=&#34;email@host.tld&#34;&#xA;Example: tuning reporting tasks email parameter /etc/apticron/apticron.conf&#xA; &#xA;Conclusion&#xA;&#xA;In this article we revisited ways to install nginx on various platforms. Even though configuration was beyond the scope of this article, we managed to get everyday quick refreshers out. &#xA;&#xA;Reading list &#xA;&#xA;Configuring nodejs applications&#xA;&#xA;#nodejs #homebrew #UnattendedUpgrades #nginx #y2020 #Jan2020 #HowTo #ConfiguringNodejsApplications #tdd #TestingNodejsApplications]]&gt;</description>
      <content:encoded><![CDATA[<p>This article revisits essentials on how to install <code>nginx</code> non blocking single threaded multipurpose web server on development and production servers.</p>

<blockquote><p>This article has complementary materials to the <strong><em><a href="http://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></em></strong>. However, the article is designed to help both those who already bought the book, as well as the wide audience of software developers  to setup working environment.  <a href="http://bit.ly/2ZFJytb"><img src="https://snap.as/a/42OS2vs.png" alt="Testing Nodejs Applications Book Cover"/></a>
<strong><em><a href="http://bit.ly/2ZFJytb">You can grab a copy of this book on this link</a></em></strong></p></blockquote>

<h2 id="installing-nginx-on-linux" id="installing-nginx-on-linux">Installing <code>nginx</code> on Linux</h2>

<p>It is always a good idea to update the system before start working. There is no exception, even when a daily task updates automatically binaries. That can be achieved on Ubuntu and Aptitude enabled systems as following:</p>

<pre><code class="language-shell">$ apt-get update # Fetch list of available updates
$ apt-get upgrade # Upgrades current packages
$ apt-get dist-upgrade # Installs only new updates
</code></pre>

<p><em><em>Example</em>: updating aptitude binaries</em></p>

<p>At this point most of packages should be installed or upgraded. Except Packages whose PPA have been removed or not available in the registry. Installing software can be done by installing binaries, or using Ubuntu package manager.</p>

<h3 id="installing-a-nginx-on-linux-using-apt" id="installing-a-nginx-on-linux-using-apt">Installing a <code>nginx</code> on Linux using <code>apt</code></h3>

<p>Updating/Upgrading or first install of <code>nginx</code> server can be achieved with by the following commands.</p>

<pre><code class="language-shell">$ sudo add-apt-repository ppa:nginx/stable
$ sudo apt-get update 
$ sudo apt-get install - nginx 

# To restart the service:
$ sudo service nginx restart 
</code></pre>

<p><em><em>Example</em>: updating PPA and installing <code>nginx</code> binaries</em></p>

<blockquote><p>Adding <code>nginx</code> PPA in first step is only required for first installs, on a system that does not have the PPA available in the system database.</p></blockquote>

<h2 id="installing-nginx-on-macos" id="installing-nginx-on-macos">Installing <code>nginx</code> on macOS</h2>

<p>In case <code>homebrew</code> is not already available on your mac, this is how to get one up and running. On its own, <code>homebrew</code> depends on ruby runtime to be available.</p>

<blockquote><p><code>homebrew</code> is a package manager and software installation tool that makes most developer tools installation a breeze.</p></blockquote>

<pre><code class="language-shell">$ /usr/bin/ruby -e &#34;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&#34;
</code></pre>

<p><em><em>Example:</em> installation instruction as provided by <a href="https://brew.sh/">brew.sh</a></em></p>

<p>Generally speaking, this is how to install/uninstall things with <code>brew</code></p>

<pre><code class="language-shell">$ brew install wget 
$ brew uninstall wget 
</code></pre>

<p><em><em>Example</em>: installing/uninstalling <code>wget</code> binaries using <code>homebrew</code></em></p>

<blockquote><p>We have to to stress on the fact that <a href="https://brew.sh/">Homebrew</a> installs packages to their own directory and then symlinks their files into <code>/usr/local</code>.</p></blockquote>

<p>It is always a good idea to update the system before start working. And that, even when we have a daily task that automatically updates the system for us. macOS  can use <code>homebrew</code> package manager on maintenance matters. To update/upgrade or check outdated packages, following commands would help.</p>

<pre><code class="language-shell">$ brew outdated                   # lists all outdated packages
$ brew cleanup -n                 # visualize the list of things are going to be cleaned up.

$ brew upgrade                    # Upgrades all things on the system
$ brew update                     # Updates all outdated + brew itself
$ brew update &lt;formula&gt;           # Updates one formula

$ brew install &lt;formula@version&gt;    # Installs &lt;formula&gt; at a particular version.
$ brew tap &lt;formular@version&gt;/brew  # Installs &lt;formular&gt; from third party repository

# untap/re-tap a repo when previous installation failed
$ brew untap &lt;formular&gt; &amp;&amp; brew tap &lt;formula&gt;   
$ brew services start &lt;formular&gt;@&lt;version&gt;
</code></pre>

<p><em><em>Example</em>: key commands to work with <code>homebrew</code> cli</em></p>

<blockquote><p>For more informations, visit: <a href="https://docs.brew.sh/FAQ">Homebrew ~ FAQ</a>.</p></blockquote>

<h3 id="installing-a-nginx-on-a-mac-using-homebrew" id="installing-a-nginx-on-a-mac-using-homebrew">Installing a <code>nginx</code> on a Mac using <code>homebrew</code></h3>

<pre><code class="language-shell">$ brew install nginx@1.17.8  # as in &lt;formula&gt;@&lt;version&gt;
</code></pre>

<p><em><em>Example</em>: installing <code>nginx</code> using <code>homebrew</code></em></p>

<h2 id="installing-nginx-on-a-windows-machine" id="installing-nginx-on-a-windows-machine">Installing <code>nginx</code> on a Windows machine</h2>

<p>MacOs comes with Python and Ruby already enabled, these two languages are somehow required to run successfully a <code>nodejs</code> environment on a Mac. This is an easy target as <a href="https://nginx.org/en/docs/windows.html"><code>nginx</code></a> gives windows binaries that we can download and install on a couple of clicks.</p>

<h2 id="automated-upgrades" id="automated-upgrades">Automated upgrades</h2>

<p>Before we dive into automatic upgrades, we should consider nuances associated to managing an <code>nginx</code> deployment. The updates fall into two major, quite interesting, categories: <strong><em>patch</em></strong> updates and <strong><em>version upgrades</em></strong>.</p>

<p>Following the <a href="https://semver.org/">SemVer ~ <em>aka Semantic Versioning</em></a> standard, it is not recommended to consider <strong><em>minor</em></strong>/<strong><em>major</em></strong> versions for automated upgrades. One of the reasons being that these versions are subject to introducing breaking changes or incompatibility between two versions.  On the other hand, patches are less susceptible to introduce breaking changes, whence ideal candidates for automated upgrades. Another among other reasons, being that security fixes are released as patches to a minor version.</p>

<p>In case of a WebServer, breaking changes may be introduced when a critical configuration setting is added, or dropped between two successive versions.</p>

<blockquote><p>We should highlight that it is always better to upgrade at deployment time. The process is even easier in containerized context. We should also automate only patches, to avoid to miss security patches.</p></blockquote>

<p>In the context of Linux, we will use the <strong><em>unattended-upgrades</em></strong> package to do the work.</p>

<pre><code class="language-shell">$ apt-get install unattended-upgrades apticron
</code></pre>

<p><em><em>Example</em>: install unattended-upgrades</em></p>

<p>Two things to fine-tune to make this solution work are: to enable a blacklist of packages we do not to automatically update, and two, to enable particular packages we would love to update on a periodical basis. That is compiled in the following shell scripts.</p>

<pre><code class="language-shell">Unattended-Upgrade::Allowed-Origins {
//  &#34;${distro_id}:${distro_codename}&#34;;
    &#34;${distro_id}:${distro_codename}-security&#34;; # upgrading security patches only 
//   &#34;${distro_id}:${distro_codename}-updates&#34;;  
//  &#34;${distro_id}:${distro_codename}-proposed&#34;;
//  &#34;${distro_id}:${distro_codename}-backports&#34;;
};

Unattended-Upgrade::Package-Blacklist {
    &#34;vim&#34;;
};
</code></pre>

<p><em><em>Example</em>: fine-tune the blacklist and whitelist in <code>/etc/apt/apt.conf.d/50unattended-upgrades</code></em></p>

<p>The next step is necessary to make sure  <strong><em>unattended-upgrades</em></strong> download, install and cleanups tasks have a default period: once, twice a day or a week.</p>

<pre><code class="language-shell">APT::Periodic::Update-Package-Lists &#34;1&#34;;            # Updates package list once a day
APT::Periodic::Download-Upgradeable-Packages &#34;1&#34;;   # download upgrade candidates once a day
APT::Periodic::AutocleanInterval &#34;7&#34;;               # clean week worth of unused packages once a week
APT::Periodic::Unattended-Upgrade &#34;1&#34;;              # install downloaded packages once a day
</code></pre>

<p><em><em>Example</em>: tuning the tasks parameter <code>/etc/apt/apt.conf.d/20auto-upgrades</code></em></p>

<p>This approach works on Linux(Ubuntu), especially deployed in production, but not Windows nor macOS. The last issue, is to be able to report problems when an update fails, so that a human can intervene whenever possible. That is where the second tool <code>apticron</code> in first paragraph intervenes. To make it work, we will specify which email to send messages to, and that will be all.</p>

<pre><code class="language-shell">EMAIL=&#34;&lt;email&gt;@&lt;host.tld&gt;&#34;
</code></pre>

<p><em><em>Example</em>: tuning reporting tasks email parameter <code>/etc/apticron/apticron.conf</code></em></p>

<h2 id="conclusion" id="conclusion">Conclusion</h2>

<p>In this article we revisited ways to install <code>nginx</code> on various platforms. Even though <strong><em><a href="https://getsimple.works/how-to-configure-nodejs-applications#configure-nginx-to-run-with-a-nodejs-server">configuration was beyond the scope of this article</a></em></strong>, we managed to get everyday quick refreshers out.</p>

<h2 id="reading-list" id="reading-list">Reading list</h2>
<ul><li><a href="https://getsimple.works/how-to-configure-nodejs-applications">Configuring <code>nodejs</code> applications</a></li></ul>

<p><a href="https://getsimple.works/tag:nodejs" class="hashtag"><span>#</span><span class="p-category">nodejs</span></a> <a href="https://getsimple.works/tag:homebrew" class="hashtag"><span>#</span><span class="p-category">homebrew</span></a> <a href="https://getsimple.works/tag:UnattendedUpgrades" class="hashtag"><span>#</span><span class="p-category">UnattendedUpgrades</span></a> <a href="https://getsimple.works/tag:nginx" class="hashtag"><span>#</span><span class="p-category">nginx</span></a> <a href="https://getsimple.works/tag:y2020" class="hashtag"><span>#</span><span class="p-category">y2020</span></a> <a href="https://getsimple.works/tag:Jan2020" class="hashtag"><span>#</span><span class="p-category">Jan2020</span></a> <a href="https://getsimple.works/tag:HowTo" class="hashtag"><span>#</span><span class="p-category">HowTo</span></a> <a href="https://getsimple.works/tag:ConfiguringNodejsApplications" class="hashtag"><span>#</span><span class="p-category">ConfiguringNodejsApplications</span></a> <a href="https://getsimple.works/tag:tdd" class="hashtag"><span>#</span><span class="p-category">tdd</span></a> <a href="https://getsimple.works/tag:TestingNodejsApplications" class="hashtag"><span>#</span><span class="p-category">TestingNodejsApplications</span></a></p>
]]></content:encoded>
      <guid>https://getsimple.works/how-to-install-nginx</guid>
      <pubDate>Fri, 31 Jan 2020 22:49:00 +0000</pubDate>
    </item>
    <item>
      <title>How to install an SSL certificate</title>
      <link>https://getsimple.works/how-to-install-an-ssl-certificate?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[Your encryption will need keys&#xA;---&#xA;&#xA;As opposed to other most SSL certificate issuers, Let&#39;s encrypt is not only free to use but also easy to install and update. This write-up highlights steps I followed to install mine on both Hoo.gy.  &#xA;&#xA;  This article has complementary materials to the Testing nodejs Applications book. However, the article is designed to help both those who already bought the book, as well as the wide audience of software developers  to setup working environment.  Testing Nodejs Applications Book Cover&#xA;You can grab a copy of this book on this link&#xA;&#xA;The motivation to write this article is threefold. First, this article serves as a reference for future needs, using Let&#39;s encrypt. Second, sharing experience with developer community is another form of learning. Third, as a token of appreciation to the team that democratizes this core part of security infrastructure. &#xA;&#xA;  This blog was first published under the title: &#34;How to install Let&#39;s Encypt SSL certificate on ubuntu and nginx server &#34; on dev.to and Medium.&#xA;&#xA;In this article you will learn:&#xA;&#xA;--&#xA;&#xA;What are required binaries, and how to install those&#xA;How to generate required Keys and Certificates  &#xA;How to install certificate(s) on an nginx instance&#xA;How to enforce HTTS redirection&#xA;How to automate certificate (Auto-)renewal&#xA;&#xA;  Acknowledgments: To my friend and security nerd @jcuwimpuhwe for proof-reading and idea enrichments.  &#xA;&#xA;Install necessary software &#xA;&#xA;Hoo.gy runs on Ubuntu 14 LTS Linux box located at NYC DigitalOcean datacenter. The NodeJS web server is coupled with Nginx. From this perspective, I will suppose your system runs a similar stack.&#xA;&#xA;Certificate Issuance is done via a bot, Certbot, and covers a wide variety of Operating Systems and Web Servers. First, the step was to update and install latest packages, as well as making sure Ubuntu includes a new source of packages.&#xA;&#xA;$ sudo apt-get update&#xA;$ sudo apt-get install software-properties-common&#xA;$ sudo add-apt-repository ppa:certbot/certbot&#xA;$ sudo apt-get update&#xA;$ sudo apt-get install python-certbot-nginx &#xA;The second step installs certbot on the box. The following command is good for Nginx server, but more can be found at eff.org.&#xA;&#xA;There are two possible modes to generate SSL certificates. That is going to be the subject of the following section.&#xA;&#xA;Generate Key and Certificate &#xA;&#xA;The default mode is designed for regular Linux users. Everything is taken care of after you run the next command. Certbot generates proper keys+certificate and automatically update Nginx configuration files. &#xA;&#xA; $ sudo certbot --nginx &#xA;&#xA;For more advanced users, who rather like they key+certificate, and install certificates as it pleases them, this command will help them: &#xA;&#xA; $ sudo certbot --nginx certonly&#xA;&#xA;After generating private key and certificate, in addition, you will need to install certificates, re-enforce HTTPS redirection, and to automate certificate renewals.&#xA;&#xA;Install Certificate(s) on Nginx&#xA;&#xA;Since you are already running Nginx in production, chances are you don&#39;t want anything to mess with your custom configurations. The second command gives you just that. There are two ways to do install certificates: first is to keep your configurations intact, and symlink new certificates. The second is obviously to change configuration links to a new location. I preferred the latter.&#xA;&#xA;in /etc/nginx/sites-enabled/[your-config-file]&#xA;server{&#xA;  ...  &#xA;  listen 443 ssl;&#xA;  servername example.com;&#xA;  sslcertificate /etc/letsencrypt/live/example.com/fullchain.pem;&#xA;  sslcertificatekey /etc/letsencrypt/live/example.com/privkey.pem;  &#xA;  ...&#xA;}&#xA;&#xA;For some reasons, I was accustomed to chained.crt for certificate and key.crt for the keys. The switch is not that difficult though. Certbot generates same files under slightly different names: privatekey.pem for keys, and fullchain.pem for certificates.&#xA;&#xA;Enforce HTTPS redirection &#xA;&#xA;There is a lot of discussions on this topic. Software developers are the worst people to have a discussion with. We always end up in tribalism, and who does it better. One way that made sense in my case, was to create a new server block in existing configuration file and redirect any request to marching this new server block, to a server block that listens only to HTTPS. The new block looks somehow like the following: &#xA;&#xA;server{&#xA; listen 80;&#xA; servername example.com www.example.com;&#xA; &#xA; # redirect, and rewrite all links to https://example.com &#xA; return 301 https://example.com$requesturi;&#xA; &#xA; # Alternatively: if you want to forward without rewriting requested URL &#xA; return 301 https://$servername$requesturi;&#xA;}&#xA;&#xA;Customization of nginx configuration can be a whole new topic on its own, but I cannot close this post without talking about two things: auto-renewal(using a cron job) and redirect all traffic to secure channel. &#xA;&#xA;Automatic renewal&#xA;&#xA;SSL certificates issues by Let&#39;s encrypt last for 90 days. Which is not a bad thing on its own. If you have 1000+ servers to update every 90 days, though ... that would be a nightmare. Whence you need some sort of automation. How to go about that, is the last topic in this blog post. &#xA;&#xA;First of all, to renew certificate from Let&#39;s Encrypt takes a second ... if everything works according to the plan. &#xA;&#xA;$ sudo certbot renew --dry-run&#xA;or simply:&#xA;$ sudo certbot renew&#xA;restart the nginx server&#xA;$ sudo nginx restart &#xA;&#xA;If you are lucky to have a smaller configuration and used auto-renewal strategy, you may have a cronjob similar to the following:&#xA;&#xA;file: /etc/cron.d/certbot&#xA;0 /12    root test -x /usr/bin/certbot -a \! -d /run/systemd/system &amp;&amp; perl -e &#39;sleep int(rand(3600))&#39; &amp;&amp; certbot -q renew&#xA;&#xA;Code snippet from Ishigoya ~ Serverfault &#xA;&#xA;It is possible to customize frequency, and restart command. The cronjob gives you a way to calibrate dates by using this star format: cronjob [minute, hour, the day of the month, month, the day of week].  &#xA;&#xA;This cron runs every day around 5:30 server time: 30 5    ...   &#xA;This one runs same time, every bi-monthly(1st and 15th) 30 5 1,15   ... &#xA;This last one runs same time, every two months: 30 5  /2  &#xA;&#xA;So your cronjob may end up looking like the following if you wish to renew certificates every day around 5:30 server time.&#xA;&#xA;30 5    certbot renew --post-hook &#34;service nginx restart&#34;&#xA;alternatively: using systemctrl &#xA;30 5   * certbot renew --post-hook &#34;systemctl reload nginx&#34;&#xA;&#xA;Please consider a donation for this service to service at Let&#39;s Encrypt.Even though thoughts discussed in this article seems simple(not to say naive security-wise), there are enhancements done atop Let’s Encrypt foundations, that makes this choice rock solid. If you work in Containers environment, especially Kubernetes, you should check Kelsey Hightower’s Kube Cert Manager project on Github. Netflix’s Lemur is another alternative to manage certificates, you can read an introductory article here.&#xA;&#xA;Reading list&#xA;&#xA;How to setup SSL Let’s Encrypt on Heroku for free&#xA;WebSockets Over SSL With Node.js and Nginx&#xA;More on Nginx HTTPS redirection discussions: 1, 2, 3 &#xA;Introducing Lemur&#xA;Elliptic Curve Private Key Structure&#xA;&#xA;#nginx #ssl #letsencrypt #devops #HowTo #TestingNodejsApplications]]&gt;</description>
      <content:encoded><![CDATA[<p><img src="https://cdn-images-1.medium.com/max/800/0*mw__iDefkSLbVuki." alt="Your encryption will need keys"/></p>

<hr/>

<p>As opposed to other most SSL certificate issuers, <em><a href="https://letsencrypt.org/getting-started/">Let&#39;s encrypt</a></em> is not only free to use but also easy to install and update. This write-up highlights steps I followed to install mine on both <a href="https://app.hoo.gy">Hoo.gy</a>.</p>

<blockquote><p>This article has complementary materials to the <strong><em><a href="http://bit.ly/2ZFJytb">Testing <code>nodejs</code> Applications book</a></em></strong>. However, the article is designed to help both those who already bought the book, as well as the wide audience of software developers  to setup working environment.  <a href="http://bit.ly/2ZFJytb"><img src="https://snap.as/a/42OS2vs.png" alt="Testing Nodejs Applications Book Cover"/></a>
<strong><em><a href="http://bit.ly/2ZFJytb">You can grab a copy of this book on this link</a></em></strong></p></blockquote>

<p>The motivation to write this article is threefold. First, this article serves as a reference for future needs, using <em><a href="https://letsencrypt.org/getting-started/">Let&#39;s encrypt</a></em>. Second, sharing experience with developer community is another form of learning. Third, as a token of appreciation to <a href="https://letsencrypt.org/isrg/">the team that democratizes</a> this core part of security infrastructure.</p>

<blockquote><p>This blog was first published under the title: <em>“How to install Let&#39;s Encypt SSL certificate on <code>ubuntu</code> and <code>nginx</code> server “</em> on <a href="https://dev.to/murindwaz/how-to-install-lets-encrypt-ssl-certificate-on-ubuntu-and-nginx-server-59h">dev.to</a> and <a href="https://medium.com/hoopeez/how-to-install-lets-encrypt-ssl-certificate-on-ubuntu-and-nginx-server-ffa363b94723">Medium</a>.</p></blockquote>

<p><strong>In this article you will learn</strong>:</p>

<p><strong>—</strong></p>
<ul><li>What are required binaries, and how to install those</li>
<li>How to generate required Keys and Certificates<br/></li>
<li>How to install certificate(s) on an <code>nginx</code> instance</li>
<li>How to enforce HTTS redirection</li>
<li>How to automate certificate (Auto-)renewal</li></ul>

<blockquote><p>Acknowledgments: To my friend and security nerd <em><a href="https://twitter.com/jc_uwimpuhwe">@jc_uwimpuhwe</a></em> for proof-reading and idea enrichments.</p></blockquote>

<h2 id="install-necessary-software" id="install-necessary-software">Install necessary software</h2>

<p><strong><a href="https://app.hoo.gy">Hoo.gy</a></strong> runs on <strong>Ubuntu 14 LTS</strong> Linux box located at NYC <a href="https://www.digitalocean.com/">DigitalOcean</a> datacenter. The NodeJS web server is coupled with <strong>Nginx</strong>. From this perspective, I will suppose your system runs a similar stack.</p>

<p>Certificate Issuance is done via a bot, <a href="https://certbot.eff.org/#ubuntutrusty-nginx">Certbot</a>, and covers a wide variety of Operating Systems and Web Servers. First, the step was to update and install latest packages, as well as making sure Ubuntu includes a new source of packages.</p>

<pre><code class="language-shell">$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-nginx 
</code></pre>

<p>The second step installs <a href="https://certbot.eff.org/#ubuntutrusty-nginx">certbot</a> on the box. The following command is good for Nginx server, but more can be found at <a href="https://certbot.eff.org/">eff.org</a>.</p>

<p>There are two possible modes to generate SSL certificates. That is going to be the subject of the following section.</p>

<h2 id="generate-key-and-certificate" id="generate-key-and-certificate">Generate Key and Certificate</h2>

<p>The default mode is designed for regular Linux users. Everything is taken care of after you run the next command. Certbot generates proper keys+certificate and automatically update Nginx configuration files.</p>

<pre><code class="language-shell"> $ sudo certbot --nginx 
</code></pre>

<p>For more advanced users, who rather like they key+certificate, and install certificates as it pleases them, this command will help them:</p>

<pre><code class="language-shell"> $ sudo certbot --nginx certonly
</code></pre>

<p>After generating private key and certificate, in addition, you will need to <em>install certificates</em>, <em>re-enforce HTTPS redirection</em>, and to <em>automate certificate renewals</em>.</p>

<h2 id="install-certificate-s-on-nginx" id="install-certificate-s-on-nginx">Install Certificate(s) on Nginx</h2>

<p>Since you are already running Nginx in production, chances are you don&#39;t want anything to mess with your custom configurations. The second command gives you just that. There are two ways to do install certificates: first is to keep your configurations intact, and <strong>symlink</strong> new certificates. The second is obviously to change configuration links to a new location. I preferred the latter.</p>

<pre><code class="language-shell"># in /etc/nginx/sites-enabled/[your-config-file]
server{
  ...  
  listen 443 ssl;
  server_name example.com;
  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;  
  ...
}
</code></pre>

<p>For some reasons, I was accustomed to <strong>chained.crt</strong> for certificate and <strong>key.crt</strong> for the keys. The switch is not that difficult though. Certbot generates same files under slightly different names: <strong>privatekey.pem</strong> for keys, and <strong>fullchain.pem</strong> for certificates.</p>

<h2 id="enforce-https-redirection" id="enforce-https-redirection">Enforce HTTPS redirection</h2>

<p>There is a lot of discussions on this topic. Software developers are the worst people to have a discussion with. We always end up in tribalism, and who does it better. One way that made sense in my case, was to create a new server block in existing configuration file and redirect any request to marching this new server block, to a server block that listens only to HTTPS. The new block looks somehow like the following:</p>

<pre><code class="language-shell">server{
 listen 80;
 server_name example.com www.example.com;
 
 # redirect, and rewrite all links to https://example.com 
 return 301 https://example.com$request_uri;
 
 # Alternatively: if you want to forward without rewriting requested URL 
 return 301 https://$server_name$request_uri;
}
</code></pre>

<p>Customization of nginx configuration can be a whole new topic on its own, but I cannot close this post without talking about two things: auto-renewal(using a cron job) and redirect all traffic to secure channel.</p>

<h2 id="automatic-renewal" id="automatic-renewal">Automatic renewal</h2>

<p>SSL certificates issues by <em><strong>Let&#39;s encrypt</strong></em> last for 90 days. Which is not a bad thing on its own. If you have 1000+ servers to update every 90 days, though ... that would be a nightmare. Whence you need some sort of automation. How to go about that, is the last topic in this blog post.</p>

<p>First of all, to renew certificate from Let&#39;s Encrypt takes a second ... if everything works according to the plan.</p>

<pre><code class="language-shell">$ sudo certbot renew --dry-run
# or simply:
# $ sudo certbot renew
# restart the nginx server
$ sudo nginx restart 
</code></pre>

<p>If you are lucky to have a smaller configuration and used auto-renewal strategy, you may have a cronjob similar to the following:</p>

<pre><code class="language-shell"># file: /etc/cron.d/certbot
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system &amp;&amp; perl -e &#39;sleep int(rand(3600))&#39; &amp;&amp; certbot -q renew
</code></pre>

<p><em>Code snippet from <a href="https://serverfault.com/a/879711">Ishigoya ~ Serverfault</a></em></p>

<p>It is possible to customize frequency, and restart command. The cronjob gives you a way to calibrate dates by using this star format: cronjob [minute, hour, the day of the month, month, the day of week].</p>
<ul><li>This cron runs every day around 5:30 server time: _30 5 * * * ... _<br/></li>
<li>This one runs same time, every bi-monthly(1st and 15th) <em>30 5 1,15 * * ...</em></li>
<li>This last one runs same time, every two months: <em>30 5 * */2 *</em></li></ul>

<p>So your cronjob may end up looking like the following if you wish to renew certificates every day around 5:30 server time.</p>

<pre><code class="language-shell">30 5 * * * certbot renew --post-hook &#34;service nginx restart&#34;
# alternatively: using systemctrl 
# 30 5 * * * certbot renew --post-hook &#34;systemctl reload nginx&#34;
</code></pre>

<p>Please consider a donation for this service to service at <a href="https://letsencrypt.org/donate/">Let&#39;s Encrypt</a>.Even though thoughts discussed in this article seems simple(not to say naive security-wise), there are enhancements done atop Let’s Encrypt foundations, that makes this choice rock solid. If you work in Containers environment, especially Kubernetes, you should check <a href="https://twitter.com/kelseyhightower">Kelsey Hightower’s</a> <a href="https://github.com/kelseyhightower/kube-cert-manager">Kube Cert Manager</a> project on Github. Netflix’s <a href="https://github.com/Netflix/lemur">Lemur</a> is another alternative to manage certificates, you can read an <a href="https://medium.com/netflix-techblog/introducing-lemur-ceae8830f621">introductory article here</a>.</p>

<h2 id="reading-list" id="reading-list">Reading list</h2>
<ul><li><a href="https://medium.com/should-designers-code/how-to-set-up-ssl-with-lets-encrypt-on-heroku-for-free-266c185630db">How to setup SSL Let’s Encrypt on Heroku for free</a></li>
<li><a href="https://www.exratione.com/2013/06/websockets-over-ssl-with-nodejs-and-nginx/">WebSockets Over SSL With Node.js and Nginx</a></li>
<li>More on Nginx HTTPS redirection discussions: <a href="https://serverfault.com/a/258424">1</a>, <a href="https://bjornjohansen.no/redirect-to-https-with-nginx">2</a>, <a href="https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#using-if">3</a></li>
<li><a href="https://medium.com/netflix-techblog/introducing-lemur-ceae8830f621">Introducing Lemur</a></li>
<li><a href="https://tools.ietf.org/html/rfc5915">Elliptic Curve Private Key Structure</a></li></ul>

<p><a href="https://getsimple.works/tag:nginx" class="hashtag"><span>#</span><span class="p-category">nginx</span></a> <a href="https://getsimple.works/tag:ssl" class="hashtag"><span>#</span><span class="p-category">ssl</span></a> <a href="https://getsimple.works/tag:letsencrypt" class="hashtag"><span>#</span><span class="p-category">letsencrypt</span></a> <a href="https://getsimple.works/tag:devops" class="hashtag"><span>#</span><span class="p-category">devops</span></a> <a href="https://getsimple.works/tag:HowTo" class="hashtag"><span>#</span><span class="p-category">HowTo</span></a> <a href="https://getsimple.works/tag:TestingNodejsApplications" class="hashtag"><span>#</span><span class="p-category">TestingNodejsApplications</span></a></p>
]]></content:encoded>
      <guid>https://getsimple.works/how-to-install-an-ssl-certificate</guid>
      <pubDate>Fri, 31 Jan 2020 22:00:00 +0000</pubDate>
    </item>
  </channel>
</rss>