<?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>DEV Community: shiva kumar</title>
    <description>The latest articles on DEV Community by shiva kumar (@rshiva).</description>
    <link>https://dev.to/rshiva</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%2F153654%2F3b44493d-e6ea-4784-a95a-315a0d390fd8.jpg</url>
      <title>DEV Community: shiva kumar</title>
      <link>https://dev.to/rshiva</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rshiva"/>
    <language>en</language>
    <item>
      <title>How to remove Nginx server  version and  name.</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Tue, 22 Feb 2022 22:12:58 +0000</pubDate>
      <link>https://dev.to/rshiva/how-to-nginx-remove-version-and-name-50ek</link>
      <guid>https://dev.to/rshiva/how-to-nginx-remove-version-and-name-50ek</guid>
      <description>&lt;p&gt;Hackers mostly exploit, when they know server name and its version. We can reduce the chances first by hiding the name and version of the Nginx. Secondly, by regularly updating the tools we use.&lt;br&gt;
This quick post will guide you on renaming the Nginx server name and remove version from the headers&lt;br&gt;
If you haven't install Nginx or you dont know how to install Nginx in a ubuntu machine you can follow this &lt;a href="https://dev.to/rshiva/welcome-to-nginx-part-i-58mn"&gt;tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can check if the server is running by using below command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service nginx status 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see when request the server, what we get in response header&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu@ip-172-31-37-234:~$ curl -I localhost

HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Tue, 22 Feb 2022 20:57:32 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 22 Feb 2022 20:56:10 GMT
Connection: keep-alive
ETag: "62154dea-264"
Accept-Ranges: bytes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To rename the default server we need a directive called more_set_headers but this doesn't comes default with Nginx we need to install a dynamic module called &lt;a href="https://github.com/openresty/headers-more-nginx-module"&gt;headers-more-nginx-module&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have installed nginx ubuntu package, you need download the same version of Nginx already installed. This need to be done to compile the dynamic module.&lt;br&gt;
Lets download and unzip the nginx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget http://nginx.org/download/nginx-1.18.0.tar.gz

tar -xvzf nginx-1.18.0.tar.gz

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

&lt;/div&gt;



&lt;p&gt;Since have already installed nginx we can view the list of modules installed. You can do that by using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nginx -V 

nginx version: nginx/1.18.0 (Ubuntu)
built with OpenSSL 1.1.1f  31 Mar 2020
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-BUo7Uw/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module

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

&lt;/div&gt;



&lt;p&gt;Lets copy the output and pass them when recompiling the nginx-with-headers-more module&lt;/p&gt;

&lt;p&gt;Let's download and install the nginx-with-headers-more module&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/openresty/headers-more-nginx-module.git 

cd nginx-1.18.0/

./configure  --add-dynamic-module=/home/ubuntu/headers-more-nginx-module  &amp;lt;--with... paste the previously installed module from above nginx -V command&amp;gt;

make 

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

&lt;/div&gt;



&lt;p&gt;Once its done we have module in /home/ubuntu/nginx-1.18.0/objs directory. We need to move this to existing installed nginx modules directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo cp ngx_http_headers_more_filter_module.so /usr/lib/nginx/modules/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the headers-more-nginx-module is available to use. Go to the nginx.conf file include the installed module and add both directives to http block&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
load_module modules/ngx_http_headers_more_filter_module.so;

events {
        worker_connections 768;
}

http {
        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        server_tokens off;
        more_set_headers 'Server: Gandalf';  #Gandalf will protect your server from balrog.
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart the nginx server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service nginx restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let check again the response header&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -I localhost
HTTP/1.1 200 OK
Date: Tue, 22 Feb 2022 21:57:08 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 22 Feb 2022 20:56:10 GMT
Connection: keep-alive
ETag: "62154dea-264"
Server: Gandalf
Accept-Ranges: bytes

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

&lt;/div&gt;



&lt;p&gt;If you want complete remove the server name, pass server name empty like this in nginx.conf file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;more_set_headers 'Server: ';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; curl -I localhost
HTTP/1.1 200 OK
Date: Tue, 22 Feb 2022 21:58:02 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 22 Feb 2022 20:56:10 GMT
Connection: keep-alive
ETag: "62154dea-264"
Accept-Ranges: bytes

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

&lt;/div&gt;



&lt;p&gt;Congratulations! You have successfully renamed the server name and removed the version.&lt;br&gt;
Hope this post was helpful. If you enjoyed this post, share it.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>devops</category>
      <category>security</category>
      <category>webdev</category>
    </item>
    <item>
      <title>SSHing from Ubuntu to windows</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Wed, 19 Jan 2022 21:11:53 +0000</pubDate>
      <link>https://dev.to/rshiva/sshing-from-ubuntu-to-windows-101m</link>
      <guid>https://dev.to/rshiva/sshing-from-ubuntu-to-windows-101m</guid>
      <description>&lt;p&gt;Recently I was trying to access windows server 2016 from ubuntu 20.04 without password. Best way to do that using shh but windows server 2016 doesn't come with ssh installed. Download the &lt;a href="https://github.com/PowerShell/Win32-OpenSSH/releases/tag/V8.6.0.0p1-Beta"&gt;OpenSSH-Win64.zip &lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7LfPT6xJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7ox4iunwcsa14dscfev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7LfPT6xJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7ox4iunwcsa14dscfev.png" alt="Download" width="880" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Extract the file in C:\Program Files\, after that open sshd_Config_default with notepad and uncomment the line  port 22. Shh connect the remote machine in port 22. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vpOfi__d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lh53ok7paysymo8ty15x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vpOfi__d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lh53ok7paysymo8ty15x.png" alt="uncomment port 22" width="880" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now open powershell and run the following commands&lt;/p&gt;

&lt;p&gt;&lt;code&gt;powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Allow inbound for ssh on port 22&lt;br&gt;
&lt;code&gt;New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Start sshd, this will also create host key in C:\ProgramData\ssh&lt;/p&gt;

&lt;p&gt;&lt;code&gt;net start sshd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Check if the service is running &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Get-Service -Name ssh-agent,sshd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jFofxpbU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mv38rg21xbv5pvy51swd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jFofxpbU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mv38rg21xbv5pvy51swd.png" alt="service running" width="840" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From your powershell create a new file &lt;br&gt;
&lt;code&gt;New-Item -ItemType file "C:\ProgramData\ssh\administrators_authorized_keys"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Copy the public key from client ubuntu machine and append it to adminstrators_athorized_keys file. Creating a public key can be done using ssh-keygen in Ubuntu&lt;/p&gt;

&lt;p&gt;Restart the service using the command in powershell&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Restart-Service -Name sshd, ssh-agent -Force&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ssh Administrator@windows-ip-address&lt;/code&gt;&lt;br&gt;
Now from ubuntu machine you can successfully ssh to windows machine.&lt;/p&gt;

&lt;p&gt;Hope this helps. Follow me for quick tips and solution for daily challenges&lt;/p&gt;

&lt;p&gt;Reference: &lt;br&gt;
&lt;a href="https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement"&gt;OpenSSH Key management&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/PowerShell/Win32-OpenSSH/wiki/DefaultShell"&gt;Win32-OpenSSH&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ubuntu</category>
      <category>devops</category>
      <category>linux</category>
    </item>
    <item>
      <title>Creating Pipeline in Jenkins</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Tue, 04 Jan 2022 21:51:47 +0000</pubDate>
      <link>https://dev.to/rshiva/creating-pipeline-in-jenkins-1bkd</link>
      <guid>https://dev.to/rshiva/creating-pipeline-in-jenkins-1bkd</guid>
      <description>&lt;p&gt;If you want to get started in DevOps, Jenkins is most important and handy software you should learn.In this article, I will run you through how to install Jenkins and create first  Pipeline&lt;/p&gt;

&lt;p&gt;Jenkins can be installed in numerous ways, I will be using  docker to run the jenkins locally.&lt;/p&gt;

&lt;p&gt;To run the below command you need docker.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run --name jenkin-master&lt;br&gt;
 -d -v /Users/shiva/jenkins_home:/var/jenkins_home &lt;br&gt;
 -p 8080:8080 jenkins/jenkins:jdk11&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command downloads the jenkins:jdk11 image and runs it, &lt;strong&gt;&lt;em&gt;-v&lt;/em&gt;&lt;/strong&gt; create a volume to maintain data persistence, runs the Jenkins in port 8080 with name jenkin-master&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt; to access the Jenkins. You will see below screen&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs02py47v4xqrogmg1vvb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs02py47v4xqrogmg1vvb.png" alt="First screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To access the path given in the Jenkins page, we need to log into the docker image with below command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker exec -it jenkin-master /bin/bash&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;-it&lt;/em&gt;&lt;/strong&gt; stands for interactive terminal&lt;/p&gt;

&lt;p&gt;Once you are in, use the below command to get the password&lt;br&gt;
&lt;code&gt;cat /var/jenkins_home/secrets/initialAdminPassword&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In Next screen, select &lt;em&gt;Install suggested plugins&lt;/em&gt;, once its done you can create a new admin user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sta8kr1a6qze91ywoi3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9sta8kr1a6qze91ywoi3.png" alt="create new user"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;click next and start using jenkins&lt;/p&gt;

&lt;p&gt;You will land on this page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpj9705yd76bb8ndw1ofl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpj9705yd76bb8ndw1ofl.png" alt="Home page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the left you will see the menu, click on &lt;strong&gt;&lt;em&gt;New Item&lt;/em&gt;&lt;/strong&gt; , then select &lt;strong&gt;&lt;em&gt;Pipeline&lt;/em&gt;&lt;/strong&gt; and give it a name &lt;em&gt;&lt;strong&gt;firstJob&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Pipeline is a series of step which helps in building the software. In other words, pipeline is used to implement and integrate continuous delivery. &lt;/p&gt;

&lt;p&gt;There are two types of pipeline,&lt;br&gt;
-&amp;gt; scripted &amp;amp;&lt;br&gt;
-&amp;gt; declarative&lt;br&gt;
We are going to write our first declarative pipeline.&lt;/p&gt;

&lt;p&gt;After creating your &lt;strong&gt;&lt;em&gt;firstJob&lt;/em&gt;&lt;/strong&gt; scroll down to Pipeline and write the below code in the editor&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pipeline&lt;/em&gt;&lt;/strong&gt; -&amp;gt; All the declarative scripted pipeline starts with a pipeline block&lt;br&gt;
&lt;strong&gt;&lt;em&gt;agent&lt;/em&gt;&lt;/strong&gt; -&amp;gt; instructs Jenkins to run the stages on any agent or node&lt;br&gt;
&lt;strong&gt;&lt;em&gt;stages&lt;/em&gt;&lt;/strong&gt; -&amp;gt; Stages contain one or more stage.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;stage&lt;/em&gt;&lt;/strong&gt; -&amp;gt; Stage reside inside the stages and it should have a steps block. Every stage will have a name like &lt;strong&gt;Test, Build, Deploy&lt;/strong&gt;. Here we named our stage as &lt;strong&gt;Hello&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;steps&lt;/em&gt;&lt;/strong&gt; -&amp;gt; Steps are written inside the stage and it contains list of commands or scripts that need to run. Here we just wanted to echo "Hello World."&lt;/p&gt;

&lt;p&gt;Once you have saved your first declarative Pipeline, let's run it. Click on &lt;strong&gt;&lt;em&gt;Build Now&lt;/em&gt;&lt;/strong&gt;. After the build is done, you can click on &lt;strong&gt;build number 1&lt;/strong&gt; from build history then in the left menu click on &lt;strong&gt;&lt;em&gt;Console Output&lt;/em&gt;&lt;/strong&gt; to view the output of the build&lt;/p&gt;

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

&lt;p&gt;As you can see, the "Hello World" is successfully printed in the output console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpkcwm5kxj5ua2kmpfr1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpkcwm5kxj5ua2kmpfr1.png" alt="console output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! You have created your first pipeline in Jenkins, We will use this as a base to build complete continuous delivery.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Hashify.app, Share Sensitive Data Securely !</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Fri, 25 Dec 2020 10:46:09 +0000</pubDate>
      <link>https://dev.to/rshiva/hashify-app-53h8</link>
      <guid>https://dev.to/rshiva/hashify-app-53h8</guid>
      <description>&lt;p&gt;Recently, I was involved in an audit. We used to send important files zipped and password-protected, share the password of it over email or chatting software. I  always felt uncomfortable while sharing credentials or secret messages over chatting software or email. Because it lives in the database of those chat/email companies forever, exposing you to potential security risks. That's where hashify comes to solve that itch. Our little app can help you. Signup to get notified of the launch &lt;a href="https://hashify.app"&gt;https://hashify.app&lt;/a&gt;  &lt;/p&gt;

</description>
      <category>showdev</category>
      <category>startup</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Block, Lambda, and Proc in Ruby</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Mon, 30 Nov 2020 04:13:07 +0000</pubDate>
      <link>https://dev.to/rshiva/block-vs-lambda-vs-proc-in-ruby-342p</link>
      <guid>https://dev.to/rshiva/block-vs-lambda-vs-proc-in-ruby-342p</guid>
      <description>&lt;h2&gt;
  
  
  Block
&lt;/h2&gt;

&lt;p&gt;Blocks are pieces of code between &lt;em&gt;{}&lt;/em&gt; or &lt;em&gt;do&lt;/em&gt; and &lt;em&gt;end&lt;/em&gt; keywords. We can pass parameters in the block. Blocks are not object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s1"&gt;'Hola, I'&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;do&lt;/span&gt; 
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s1"&gt;'Hola, I'&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Proc
&lt;/h2&gt;

&lt;p&gt;Block can be converted to objects using Proc. Proc is assigned to a variable and its executed by using .call method.Proc can be defined using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;proc&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Proc accepts arguments but it doesn't throw an error when called with a lesser or more argument than expected&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;my_proc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;  &lt;span class="s2"&gt;"x = &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Proc:0x00007f91ea9eada8@(irb):57&amp;gt;&lt;/span&gt;
&lt;span class="n"&gt;my_proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"x = 2"&lt;/span&gt;

&lt;span class="n"&gt;my_proc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;"x = &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, y = &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, z = &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Proc:0x00007f91eaa00e78@(irb):59&amp;gt;&lt;/span&gt;
&lt;span class="n"&gt;my_proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"x = 2, y = 3, z = "&lt;/span&gt;

&lt;span class="n"&gt;my_proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"x = 2, y = 3, z = "&lt;/span&gt;

&lt;span class="n"&gt;my_proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"x = 2, y = 3, z = 5"&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lambda
&lt;/h2&gt;

&lt;p&gt;Lambda and Proc are similar. Lambda is a little anonymous function, which can be stored in a variable.Lambda will throw error if arguments passed is less or more than expected just like function&lt;/p&gt;

&lt;p&gt;Lambda can be defined using the lambda keyword or -&amp;gt; {}&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;lambda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Hola"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;or&lt;/span&gt;

&lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Hola"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;
&lt;span class="n"&gt;my_lambda&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;lambda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;"x =  &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;my_lambda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;


&lt;span class="n"&gt;my_lambda&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;lambda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;"x = &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, y = &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, z = &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;my_lambda&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;Traceback&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;most&lt;/span&gt; &lt;span class="n"&gt;recent&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="sr"&gt;/Users/n&lt;/span&gt;&lt;span class="n"&gt;bt040&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rvm&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;gems&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ruby&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;2.6&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ruby_executable_hooks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="ss"&gt;:in&lt;/span&gt; &lt;span class="sb"&gt;`&amp;lt;main&amp;gt;'
        6: from /Users/nbt040/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `&lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="s1"&gt;'
        5: from /Users/nbt040/.rvm/rubies/ruby-2.6.3/bin/irb:23:in `&amp;lt;main&amp;gt;'&lt;/span&gt;
        &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="sr"&gt;/Users/n&lt;/span&gt;&lt;span class="n"&gt;bt040&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rvm&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;rubies&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ruby&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;2.6&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;irb&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="ss"&gt;:in&lt;/span&gt; &lt;span class="sb"&gt;`load'
        3: from /Users/nbt040/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;top&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'
        2: from (irb):67
        1: from (irb):66:in `block in irb_binding'&lt;/span&gt;
&lt;span class="no"&gt;ArgumentError&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wrong&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;given&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lambda return works like functions. Proc will return from the current context&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lambda_method&lt;/span&gt;
 &lt;span class="nb"&gt;lambda&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Returned from Lambda block"&lt;/span&gt; &lt;span class="p"&gt;}.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"return from method"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

 &lt;span class="n"&gt;lambda_method&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"return from method"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;proc_method&lt;/span&gt;
 &lt;span class="no"&gt;Proc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"Returned from the Proc block"&lt;/span&gt; &lt;span class="p"&gt;}.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"return from method"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;proc_method&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Returned from the Proc block"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Proc and Lambda behave differently in accepting the argument and how they return. Lambdas are proc but procs are not lambda. Hope this quick guide helped you in understanding Block, Proc and Lambda.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>codenewbie</category>
      <category>rails</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Quick difference in ruby's Each vs Map vs Collect vs Select</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Sat, 28 Nov 2020 04:54:34 +0000</pubDate>
      <link>https://dev.to/rshiva/quick-difference-in-ruby-s-each-vs-map-vs-collect-vs-select-1kif</link>
      <guid>https://dev.to/rshiva/quick-difference-in-ruby-s-each-vs-map-vs-collect-vs-select-1kif</guid>
      <description>&lt;p&gt;Ruby iterators simply explained with an example&lt;/p&gt;

&lt;h2&gt;
  
  
  Each vs Map vs Collect vs Select
&lt;/h2&gt;

&lt;p&gt;All of them iterators an array but the difference is on the return value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array = [1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below code prints 2,3,4,5 but returns original array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.each do |a|
  puts a+1
end
2
3
4
5
=&amp;gt; [1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Map and Collect have the same functionality with a different name. Iterates through each element and return a new array of elements returned by the block&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array.collect {|a| a + 1}
=&amp;gt; [2, 3, 4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Select iterates and return new array of elements for which given block is true&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; array.select  { |num|  num.even?  } 
[2, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Summary:
&lt;/h3&gt;

&lt;p&gt;Each -&amp;gt; returns same array&lt;br&gt;
Map &amp;amp; collect -&amp;gt; returns new array with code executed in block for each element&lt;br&gt;
Select -&amp;gt; return new array for the which give block is true&lt;/p&gt;

&lt;p&gt;In next post, we will look into more enumerable methods which are handy to know.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>codenewbie</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The Order doesn't matter anymore</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Wed, 18 Nov 2020 14:34:06 +0000</pubDate>
      <link>https://dev.to/rshiva/the-order-doesn-t-matter-anymore-3a11</link>
      <guid>https://dev.to/rshiva/the-order-doesn-t-matter-anymore-3a11</guid>
      <description>&lt;p&gt;Have you ever been in a situation where you have to remember the order of the parameter while initializing an object? This a dependency, that can be easily overcome by using a hash. Enough talk, let's see the code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before

class Employee

  def initialize(name, age, gender, department)
    @name = name
    @age =  age
    @gender = gender
    @department = department
  end

end

employee = Employee.new('Mat', 50, 'M', 'Dev')
=&amp;gt; #&amp;lt;Employee:0x00007fa700803d20 @name="Mat", @age=50, @gender="M", @department="Dev"&amp;gt;


After

class Employee

  def initialize(args)
    @name = args[:name]
    @age =  args[:age]
    @gender = args[:gender]
    @department = args[:department]
  end

end

employee = Employee.new(age: 50, department: 'Dev',name: 'Mat', gender: 'M')
=&amp;gt; #&amp;lt;Employee:0x00007fa6fc8ab060 @name="Mat", @age=50, @gender="M", @department="Dev"&amp;gt;


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

&lt;/div&gt;



&lt;p&gt;As you can see above the order doesn't matter anymore. You don't to remember parameter order to create an employee object. What if while initializing an object you have to set a default value. For this it's better to use ruby's in build method called fetch for hash&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Employee

  def initialize(args)
    @name = args.fetch(:name)
    @age =  args.fetch(:age)
    @gender = args.fetch(:gender)
    @department = args.fetch(:department, "dev")
  end

end

employee = Employee.new(name: 'Mat', age: 50, gender: 'M')

=&amp;gt; #&amp;lt;Employee:0x00007fa6fe8a1f18 @name="Mat", @age=50, @gender="M", @department="dev"&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Hope this quick tip was helpful. Share your tips in comments. Let me know if you are interested in more such tips and best practices.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
    </item>
    <item>
      <title>How To Exit Vim?</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Fri, 17 May 2019 10:50:28 +0000</pubDate>
      <link>https://dev.to/rshiva/how-to-exit-vim-54a5</link>
      <guid>https://dev.to/rshiva/how-to-exit-vim-54a5</guid>
      <description>&lt;p&gt;If you are new to Vim or you have accidentally opened this editor where you type and nothing happens and you are stuck in this plain maze and don't know how to exit? &lt;/p&gt;

&lt;p&gt;To exit you such press &lt;strong&gt;:q&lt;/strong&gt; and hit enter. Nothing happened and you are in still in Vim then press escape and then type &lt;strong&gt;:q&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that you know how to exit. Let's dig in more, there are two modes in Vim.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Insert mode&lt;/strong&gt; : Press i for insert mode. Where you can just type like a normal text editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Command mode&lt;/strong&gt; : Press ESC for command mode. Where you give commands to the editor to get things done. You can see below left-hand corner of the screen what you are typing.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;x&lt;/strong&gt; – to delete the unwanted character&lt;br&gt;
&lt;strong&gt;u&lt;/strong&gt; – to undo the last the command and U to undo the whole line&lt;br&gt;
&lt;strong&gt;CTRL-R&lt;/strong&gt; - to redo&lt;br&gt;
&lt;strong&gt;A&lt;/strong&gt; – to append text at the end&lt;br&gt;
&lt;strong&gt;:wq&lt;/strong&gt; – to save and exit&lt;br&gt;
&lt;strong&gt;:q!&lt;/strong&gt; – to trash all changes&lt;br&gt;
&lt;strong&gt;dw&lt;/strong&gt; – move the cursor to the beginning of the word to delete that word&lt;br&gt;
&lt;strong&gt;2w&lt;/strong&gt; – to move the cursor two words forward.&lt;br&gt;
&lt;strong&gt;3e&lt;/strong&gt; – to move the cursor to the end of the third word forward.&lt;br&gt;
&lt;strong&gt;0&lt;/strong&gt; (zero) to move to the start of the line.&lt;br&gt;
&lt;strong&gt;d2w&lt;/strong&gt; – which deletes 2 words .. number can be changed for deleting the number of consecutive words like d3w&lt;br&gt;
&lt;strong&gt;dd&lt;/strong&gt; - to delete the line and 2dd to delete to line .number can be changed for deleting the number of consecutive words&lt;/p&gt;

&lt;p&gt;The format for a change command is: &lt;strong&gt;operator [number] motion&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;operator&lt;/strong&gt; – is what to do, such as d for delete&lt;br&gt;
&lt;strong&gt;[number]&lt;/strong&gt; – is an optional count to repeat the motion&lt;br&gt;
&lt;strong&gt;motion&lt;/strong&gt; – moves over the text to operate on, such as w (word),&lt;br&gt;
$ (to the end of the line), etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;p&lt;/strong&gt; – puts the previously deleted text after the cursor(Type dd to delete the line and store it in a Vim register. and p to put the line)&lt;br&gt;
&lt;strong&gt;r&lt;/strong&gt; – to replace the letter e.g press re to replace the letter with e&lt;br&gt;
&lt;strong&gt;ce&lt;/strong&gt; – to change until the end of a word (place the cursor on the u in lubw it will delete ubw )&lt;br&gt;
&lt;strong&gt;ce&lt;/strong&gt; – deletes the word and places you in Insert mode&lt;br&gt;
&lt;strong&gt;G&lt;/strong&gt; – to move you to the bottom of the file.&lt;br&gt;
&lt;strong&gt;gg&lt;/strong&gt; – to move you to the start of the file.&lt;/p&gt;

&lt;p&gt;To move the cursor to specific line number press the number and then G, for example, 3 and G will move the cursor to the third line &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;%&lt;/strong&gt; – to find a matching ),], or }&lt;br&gt;
&lt;strong&gt;:s/old/new/g&lt;/strong&gt; – to substitute ‘new’ for ‘old’ where g is globally&lt;br&gt;
&lt;strong&gt;/&lt;/strong&gt; – backward search n to find the next occurrence and N to search in the opposite direction&lt;br&gt;
&lt;strong&gt;?&lt;/strong&gt; – forward search&lt;br&gt;
&lt;strong&gt;:!&lt;/strong&gt; – to run the shell commands like :!dir, :!ls&lt;br&gt;
&lt;strong&gt;:w&lt;/strong&gt; – TEST (where TEST is the filename you chose.) . Save the file&lt;br&gt;
&lt;strong&gt;v&lt;/strong&gt; – starts visual mode for selecting the lines and you can perform an operation on that like d delete&lt;br&gt;
&lt;strong&gt;:r&lt;/strong&gt; – Filename will insert the content into the current file&lt;br&gt;
&lt;strong&gt;R&lt;/strong&gt; – to replace more than one character&lt;br&gt;
&lt;strong&gt;y&lt;/strong&gt; – operator to copy text using v visual mode and p to paste it&lt;br&gt;
&lt;strong&gt;yw&lt;/strong&gt; – (copy)yanks one word&lt;br&gt;
&lt;strong&gt;o&lt;/strong&gt; – opens a line below the cursor and start Insert mode.&lt;br&gt;
&lt;strong&gt;O&lt;/strong&gt; – opens a line above the cursor.&lt;br&gt;
&lt;strong&gt;a&lt;/strong&gt; – inserts text after the cursor.&lt;br&gt;
&lt;strong&gt;A&lt;/strong&gt; – inserts text after the end of the line.&lt;br&gt;
&lt;strong&gt;e&lt;/strong&gt; – command moves to the end of a word.&lt;br&gt;
&lt;strong&gt;y&lt;/strong&gt; – operator yanks (copies) text, p puts (pastes) it.&lt;br&gt;
&lt;strong&gt;R&lt;/strong&gt; – enters Replace mode until  is pressed.&lt;br&gt;
&lt;strong&gt;ctrl-w&lt;/strong&gt; to jump from one window to another&lt;/p&gt;

&lt;p&gt;type a command :e and press ctrl+D to list all the command name starts with :e and press tab to complete the command&lt;/p&gt;

&lt;p&gt;To learn more on Vim, if you in Mac or Linux you can just type the command &lt;strong&gt;vimtutor&lt;/strong&gt;. which has detailed documentation&lt;/p&gt;

&lt;p&gt;Below are some fun way to learn Vim&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://vim-adventures.com/"&gt;Vim Adventures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.openvim.com/"&gt;Interactive VIM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://vimcasts.org/episodes/"&gt;Vim Advance&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>vim</category>
      <category>vi</category>
      <category>beginners</category>
      <category>ide</category>
    </item>
    <item>
      <title>Nginx as a Load balancer (Part-III)</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Thu, 02 May 2019 10:30:10 +0000</pubDate>
      <link>https://dev.to/rshiva/nginx-as-a-load-balancer-part-iii-39ad</link>
      <guid>https://dev.to/rshiva/nginx-as-a-load-balancer-part-iii-39ad</guid>
      <description>&lt;p&gt;Nginx as a load balancer, this is 3rd part of the series(&lt;a href="https://dev.to/rshiva/welcome-to-nginx-part-i-58mn"&gt;Part I&lt;/a&gt; and &lt;a href="https://dev.to/rshiva/welcome-to-nginx-part-ii-32kmn"&gt;Part II&lt;/a&gt;).  The first step in scaling your server. Let's keep it simple.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is load balancer?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Loadbalancer is a method used for distributing traffic across the servers. Before we get into details of load balancing, there are two ways we can scale the server. First, Vertical scaling, in this we add more computing power i.e by increasing RAM and CORE to an existing server but this will be expensive after a certain point. Second, Horizontal scaling is to add more servers of the same or different configuration and install the required application to run our web app. Below image gives a gist about vertical vs horizontal scaling&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzjpwj28f1lptdfz6w8ej.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzjpwj28f1lptdfz6w8ej.png" alt="Vertical vs horizontal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why do you need it?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To increase the application performance, availability and to decrease the latency when faced with heavy traffic. When our server cannot handle too many requests or the number of users visiting our website increases. Our application can get slow and users can get annoyed since the time taken to do any task increases. This is bad user experience. This is when we scale our servers.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Nginx as Load Balancer&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Nginx is a software load balancer. It can be used as HTTP load balancer efficiently by distributing the request across multiple application servers which will increase the app availability (even if one server goes down), performance and scalability. There are hardware load balancers which are quite expensive &amp;amp; require separate resources for maintenance and debugging, which can be become quite a tedious task. Successful &lt;a href="https://www.nginx.com/success-stories/" rel="noopener noreferrer"&gt;case studies&lt;/a&gt; of companies using nginx as a load balancer and some companies replaced their hardware load balancer with nginx.&lt;/p&gt;

&lt;p&gt;First, we will need a dedicated server where we run only nginx whose job will be just to forward the request upstream. Let's add three more application servers. Instead of pointing the application to our single server we now point our domain or first landing request to nginx load balancer. Nginx will decide where the request should be forwarded based on the techniques mentioned below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgfa0sb591p49r7sz3fb7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgfa0sb591p49r7sz3fb7.png" alt="Load balancer architecture"&gt;&lt;/a&gt;&lt;br&gt;
Image showing our architecture&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Follow the below steps to get started -&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First, let's create a config file called load_balancer.conf inside &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    cd /etc/nginx/conf
    sudo touch load_balancer.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Open the load_balancer.conf and add the below configuration. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    http {
        upstream wayne_tech {
            server server1.com;
            server server2.com;
            server server3.com;
        }

        server {
            listen 80;

            location / {
                proxy_pass http://wayne_tech;
            }
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's save this configuration file and include this file in our main configuration file and restart the server. Refer &lt;a href="https://dev.to/rshiva/welcome-to-nginx-part-ii-32kmn"&gt;Part II&lt;/a&gt; post if you need to know how it's done.&lt;/p&gt;

&lt;p&gt;server1.com, server2.com  and server3.com, IP configuration need to be added in /etc/hosts. Let's do that.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    sudo vi /etc/hosts

    192.168.1.101   server1.com
    192.168.1.102   server2.com
    192.168.1.103   server3.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now that all the configurations are done. When any request comes to the web app it lands on the load balancer and it decides where to forward the request.&lt;/p&gt;

&lt;p&gt;There are different load balancing techniques supported by nginx.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1) round-robin(default)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;By default, Round-robin algorithm is used, in which each request is given to upstream server in sequence. i.e the first request will land on server1 and second request will land on server2 and so on.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    upstream wayne_tech {&lt;br&gt;
        server server1.com;&lt;br&gt;
        server server2.com;&lt;br&gt;
        server server3.com;&lt;br&gt;
    }&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;2) least-connected&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;In this technique, nginx will not overload the server which is already processing a lot of requests; instead, it directs the requests to a less busy server. Nginx will compare each active connection with servers and send the request to a least active connection. We just need to add a least_conn directive in our upstream configuration&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    upstream wayne_tech {&lt;br&gt;
        least_conn;&lt;br&gt;
        server server1.com;&lt;br&gt;
        server server2.com;&lt;br&gt;
        server server3.com;&lt;br&gt;
    }&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;3) ip-hash&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;If you need to map a client to a particular application server,i.e to keep client persistent or to maintain a state, ip-hash can be used. Requests are distributed based on the client's IP address which is used as a hashing key to serve the request to the server. This will make sure that the same client requests are directed to the same server unless that server is down.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   upstream wayne_tech {&lt;br&gt;
        ip_hash;&lt;br&gt;
        server server1.com;&lt;br&gt;
        server server2.com;&lt;br&gt;
        server server3.com;&lt;br&gt;
    }&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;4) Weighted load balancing&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;In this method, we give weights to the servers. We can use this when our servers are not identical in configuration. For example, server1 has 16GB RAM and 8 CORE processor and whereas the other two servers have an 8GB and 4 CORE processor. Below configuration shows weight {6, 2, 2} which indicates that for every 10 requests, 60% percent of the request is given to server1 and 20% of the request is directed to server2 and remaining 20% to server3. &lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    upstream wayne_tech {&lt;br&gt;
        server server1.com weight=6;&lt;br&gt;
        server server2.com weight=2;&lt;br&gt;
        server server3.com weight=2;&lt;br&gt;
    }&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;This is the last post on nginx series. Now that you know how to set up and install a server. And if your application receiving loads of traffic and use one of these techniques to distribute the load across the server. I encourage you to dig in the nginx documentation to unwrap its power and there is an enterprise edition of nginx plus which gives you more features. I have been using Nginx for almost a decade I never felt the need for enterprise edition even though we are serving millions of request per server per day. Reach out to me if you need any help. That's all folks.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>loadbalancer</category>
      <category>architecture</category>
      <category>scaling</category>
    </item>
    <item>
      <title>Beginners guide to logrotate.</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Sun, 21 Apr 2019 12:19:01 +0000</pubDate>
      <link>https://dev.to/rshiva/what-the-hell-is-logrotate-hcl</link>
      <guid>https://dev.to/rshiva/what-the-hell-is-logrotate-hcl</guid>
      <description>&lt;p&gt;Now that you have &lt;a href="https://dev.to/rshiva/welcome-to-nginx-part-i-58mn"&gt;installed&lt;/a&gt; and &lt;a href="https://dev.to/rshiva/welcome-to-nginx-part-ii-32km"&gt;setup&lt;/a&gt; Nginx in production for your web application. Your site is getting a good amount of traffic and all the logs are written in single file. This can be cumbersome to perform a certain task on file like searching and archiving the logs. Wouldn't be easy if can write daily logs on a separate file and compress the old logs and archive it separate place this will help us in optimizing the hard disk space.&lt;/p&gt;

&lt;h2&gt;
  
  
  Welcome to logrotate.
&lt;/h2&gt;

&lt;p&gt;Logrotate is built-in ubuntu. With Logrotate we can do automatic rotation, compression, deletion and mailing the files. Each file can be rotated daily, weekly or monthly basis or when the file size becomes too large. &lt;/p&gt;

&lt;p&gt;Main logrotate configuration is in &lt;strong&gt;/etc/logrotate.conf&lt;/strong&gt; .If you look into that file which has configuration many default configuration. Before we dive into the configuration you should see below line in the file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;include /etc/logrotate.d/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Rather than writing all the process log into single file, let's create a separate configuration file so that it will be easy to maintain.First, we need to create an nginx conf file inside &lt;strong&gt;/etc/logrotate.d/&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /etc/logrotate.d/
sudo touch nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's write the below basic configuration into that file and save it. I will run you through what each line does.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/etc/nginx/log/*.log {
  daily
  rotate 15
  missingok
  compress
  delaycompress
  notifempty
  dateext
  dateformat .%Y-%m-%d
  create 664 www-data www-data
  sharedscripts
  postrotate
    [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
  endscript
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;/etc/nginx/log/*.log&lt;/strong&gt; : Is the path of logs file you want to rotate.&lt;br&gt;
&lt;strong&gt;daily&lt;/strong&gt; :  Rotate on a daily basis.&lt;br&gt;
&lt;strong&gt;size&lt;/strong&gt; : (100K/100M/100G) This will logrotate the log whenever the size of the file increases as configured.&lt;br&gt;
&lt;strong&gt;rotate 15&lt;/strong&gt;: Only last 15 log file are kept and others will be deleted. If rotate count is 0 old versions are deleted rather than rotated&lt;br&gt;
&lt;strong&gt;missingok&lt;/strong&gt; : If the log file is missing move to next file without throwing error.&lt;br&gt;
&lt;strong&gt;nomissingok&lt;/strong&gt; : If log file doesn't exist throw an error.&lt;br&gt;
&lt;strong&gt;compress&lt;/strong&gt; : It compresses the rotated file by default it uses gzip and file formats ending with .gz.&lt;br&gt;
&lt;strong&gt;delaycompress&lt;/strong&gt;: Delaycompress as the name suggest it delays compression of the log file so that previous processes after a restart or reload will be still written in the old log file so that we don't miss any logs. This will only work if you have &lt;strong&gt;compress&lt;/strong&gt; in the configuration.&lt;br&gt;
&lt;strong&gt;notifempty&lt;/strong&gt; : Do not rotate the file if it's empty.&lt;br&gt;
&lt;strong&gt;dateext&lt;/strong&gt; : Archiving the old log file with date extension rather than by number. Format for a daily extension is YYYYMMDD. This is really handy when you need to search anything on a specific date.&lt;br&gt;
&lt;strong&gt;create mode owner group&lt;/strong&gt;: This creates a new log file with mode, owner, and the group immediately after rotation.&lt;br&gt;
&lt;strong&gt;dateformat&lt;/strong&gt; : To specify the date format extension to dateext.&lt;br&gt;
&lt;strong&gt;sharedscripts&lt;/strong&gt; : Sharedscripts are used with postrotate or prerotate, any scripts added to the postscript to run only once. &lt;br&gt;
&lt;strong&gt;postrotate&lt;/strong&gt; :  Script inside the postrotate and endscript are executed after the logfile is rotated. This script does not kill the nginx process instead it sends a signal to reload the log files so that new requests are logged in the new file.&lt;br&gt;
&lt;strong&gt;prerotate&lt;/strong&gt; : Script inside this block will be executed before the logrotate.&lt;/p&gt;

&lt;p&gt;This tutorial is just to get you started with logrotate. There are many configurations in logrotate like mailing the logs to the specific email address and many more. I encourage to check the inbuild documentation(man logratote)&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>logrotate</category>
      <category>ubuntu</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Welcome to Nginx! (Part-II)</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Fri, 12 Apr 2019 06:47:24 +0000</pubDate>
      <link>https://dev.to/rshiva/welcome-to-nginx-part-ii-32km</link>
      <guid>https://dev.to/rshiva/welcome-to-nginx-part-ii-32km</guid>
      <description>&lt;p&gt;This post is the continuation of &lt;a href="https://dev.to/rshiva/welcome-to-nginx-part-i-58mn"&gt;Part-I&lt;/a&gt;. If you haven't read that article, I recommend to read that.&lt;/p&gt;

&lt;p&gt;By default nginx has some folders and files as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--64taAr0p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/piaotz3mj3e1naeuu1at.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--64taAr0p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/piaotz3mj3e1naeuu1at.png" alt="nginx_folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are interested into two main folders&lt;/p&gt;

&lt;p&gt;1) /etc/nginx/conf - Where our most of the configuration goes&lt;br&gt;
2) /etc/nginx/logs -  Server logs files resides there. They are access.log and error.log files&lt;/p&gt;

&lt;p&gt;Lets dive into &lt;strong&gt;conf folder&lt;/strong&gt; first. Conf Folder has many .conf files as mentioned below, which are for different protocols&lt;/p&gt;

&lt;p&gt;i)  fastcgi.conf - This configuration is used for  fastcgi protocol application&lt;br&gt;
ii) nginx.conf - This is configuration we are interested in, we will break down this file and go in details regarding the configuration &lt;br&gt;
iii) scgi_params - This file is used for passing request to an SCGI server&lt;br&gt;
iv) uwsgi_params - This file is used for processing request to the uwsgi application e.g used with python application &lt;br&gt;
v) mime.types - Multi Internet Mail Extension which has list of formats to support email and http&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log folder&lt;/strong&gt; has error.log and access.log. Each request gets logged in access log and whenever a request throws a error that gets logged in error.log&lt;/p&gt;

&lt;p&gt;Nginx configuration file consist of two main things, Directives and Contexts. Directives are simple single line configuration which ends with semi-colon and Contexts are top level directives that are grouped together with multiple directives.&lt;/p&gt;

&lt;p&gt;Example of Directives are&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user www-data;
include conf.d/first_nginx.conf;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;There are four main context&lt;/p&gt;

&lt;p&gt;1) events - connection processing&lt;br&gt;
2) http - for serving http/https traffic&lt;br&gt;
3) mail - for serving mail traffic&lt;br&gt;
4) stream - for steaming TCP and UDP packets&lt;/p&gt;

&lt;p&gt;Let's create a simple static page and let's configure it with nginx to access across the internet. First, let's put our project inside a folder and create a homepage.html&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir apps &amp;amp;&amp;amp; cd apps &amp;amp;&amp;amp; mkdir welcome
cd welcome &amp;amp;&amp;amp; touch homepage.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now that we have created our welcome page now let's configure this to nginx.Instead of writing inside the default nginx.conf. We are going to create a separate configuration file called &lt;br&gt;
first_nginx.conf inside /etc/nginx/conf/ . If you remember from the first post this is where we installed the nginx. Let's add below configuration and save&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
  listen 80;
  # on which port nginx should listen for request


  server_name  server_ip;
  # domain name or ip address of the server

  root         /home/ubuntu/apps/welcome/;
  # path where the project resides

  index homepage.html;
  # default page to load

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

&lt;/div&gt;

&lt;p&gt;Now let go to default nginx.conf file and include our first nginx configuration file inside http context. I have tried to explain each directive and context in single line comment&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#user  nginx;
# user and group credentials used by worker_process if a group is not specified it will be equal to the user

worker_processes  1;
# Define the number of worker_processes, an optimal value would be the number of CPU cores in the server or set to auto

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
    #Number of maximum connection can be opened by one worker process concurrently

}


http {
    include       mime.types;
    default_type  application/octet-stream;
    # This means the response is a binary file, if it is not specified the response is set to text/plain


    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    # Formatting the request data log we can configure the parameter we need in     the log.

    #access_log  logs/access.log  main;

    client_max_body_size 20M;
    # configuration to set max client body size, if the request body is greater than 20M 
    # (413 status code) Request Entity Too Large is return to client


    keepalive_timeout  65;
    # for how many seconds the connection to be alive if it takes more the 65s to process it will connection time out

    include /etc/nginx/conf/first_nginx.conf;
    # Rather than writing the all the configuration, we can write the configuration in different and include in # the default conf file to make it easier to maintain

    #gzip  on;
    # compresses the response using gzip be default it is off
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we are going to restart the server&lt;/p&gt;

&lt;p&gt;sudo service nginx restart &lt;/p&gt;

&lt;p&gt;Enter the ip address of the server in the browser .... ta-da. You did it NNN(Novice Nginx Ninja  👨🏻‍💻  )&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CJNY7NNA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/m2w2o2hajm012ljpfn2i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CJNY7NNA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/m2w2o2hajm012ljpfn2i.png" alt="home_page"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>beginners</category>
      <category>backend</category>
      <category>developer</category>
    </item>
    <item>
      <title>Welcome To Nginx! (Part-I)</title>
      <dc:creator>shiva kumar</dc:creator>
      <pubDate>Mon, 08 Apr 2019 08:30:18 +0000</pubDate>
      <link>https://dev.to/rshiva/welcome-to-nginx-part-i-58mn</link>
      <guid>https://dev.to/rshiva/welcome-to-nginx-part-i-58mn</guid>
      <description>&lt;h1&gt;
  
  
  What is Nginx?
&lt;/h1&gt;

&lt;p&gt;According to Wiki, Nginx is an open source web server which can also be used as a reverse proxy, load balancer, mail proxy, and HTTP cache. The software was created by Igor Sysoev and first publicly released in 2004. &lt;a href="https://www.zdnet.com/article/nginx-and-the-future-of-the-web-server/" rel="noopener noreferrer"&gt;Nginx&lt;/a&gt; claims to run 60% of the busiest website on the internet.&lt;br&gt;
We use Nginx mostly as a web server(with the passenger for Rails or golang application) and as a load balancer.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to install Nginx in Ubuntu?
&lt;/h1&gt;

&lt;p&gt;Two ways to install Nginx one is from the package and other is from source(recommended)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Installing from the package is very simple. This will install the latest stable version&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get install nginx

$ sudo nginx -v
  nginx version: nginx/1.10.2
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Installing Nginx from source. There are few dependencies we need to install before installing Nginx&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get install libpcre3-dev build-essential libssl-dev
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;libpcre3-dev -&amp;gt; This is basically a regular expression library&lt;/li&gt;
&lt;li&gt;libssl-dev   -&amp;gt;  This package is part of OpenSSL implementation of the SSL and TLS for a secure connection&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://packages.ubuntu.com/xenial/build-essential" rel="noopener noreferrer"&gt;build-essentail&lt;/a&gt; -&amp;gt; This package includes GNU C++ compiler, GNU C compiler  and other libraries&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;You can install on any preferred location, mostly it's installed in /opt or /etc&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ cd /etc/

    $ sudo wget http://nginx.org/download/nginx-1.10.2.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Unzipping the tar file&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ sudo tar -zxvf nginx-1.10.2.tar.gz

    $ cd /etc/nginx-1.10.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Configure the build &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ sudo ./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module

    Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library

  nginx path prefix: "/etc/nginx"
  nginx binary file: "/etc/nginx/sbin/nginx"
  nginx modules path: "/etc/nginx/modules"
  nginx configuration prefix: "/etc/nginx/conf"
  nginx configuration file: "/etc/nginx/conf/nginx.conf"
  nginx pid file: "/etc/nginx/logs/nginx.pid"
  nginx error log file: "/etc/nginx/logs/error.log"
  nginx http access log file: "/etc/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Let's build and install with the above configuration&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ sudo make 
    $ sudo make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We need to create a separate user and group for Nginx&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Installing from source does not include init file for starting and stop the Nginx during the server reboots&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ sudo vi /etc/init.d/nginx

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

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

&lt;/div&gt;

&lt;p&gt;Make the above file executable and add it to default run levels&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ sudo chmod +x /etc/init.d/nginx
    $ sudo /usr/sbin/update-rc.d -f nginx defaults
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we can start, stop, restart and check status using the below command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ sudo service nginx &amp;lt;command&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;command -&amp;gt; start, stop, restart, status&lt;/p&gt;

&lt;p&gt;You can check if nginx is running using the below command or by visiting the ip address where you have installed&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ ps aux | grep nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

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

&lt;p&gt;Congratulation! You have successfully installed Nginx.  &lt;/p&gt;

&lt;p&gt;Part II will be about, what different files inside the conf folder does, configuring Nginx to serve an application and what's the role of each block inside nginx.conf file.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>server</category>
      <category>beginners</category>
      <category>newbie</category>
    </item>
  </channel>
</rss>
