<?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: PRADEEP KUMAR</title>
    <description>The latest articles on DEV Community by PRADEEP KUMAR (@kumarpradeephk).</description>
    <link>https://dev.to/kumarpradeephk</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%2F677668%2Fc56571f0-fde9-4e8f-8c7f-39a3d58192ce.jpeg</url>
      <title>DEV Community: PRADEEP KUMAR</title>
      <link>https://dev.to/kumarpradeephk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kumarpradeephk"/>
    <language>en</language>
    <item>
      <title>WebHook integration with Stripe Payment Intents</title>
      <dc:creator>PRADEEP KUMAR</dc:creator>
      <pubDate>Fri, 25 Feb 2022 19:42:10 +0000</pubDate>
      <link>https://dev.to/kumarpradeephk/webhook-integration-with-stripe-payment-intents-2cg5</link>
      <guid>https://dev.to/kumarpradeephk/webhook-integration-with-stripe-payment-intents-2cg5</guid>
      <description>&lt;h2&gt;
  
  
  WebHook integration with Stripe Payment Intents
&lt;/h2&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A0TjqQsZ2eCEGSRyN58Levw.gif" 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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A0TjqQsZ2eCEGSRyN58Levw.gif" alt="webhook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may have heard about Webhooks when integrating payment providers Stripe, Razorpay, Dwolla, etc in your application. I was working on one of the rails applications and had to integrate Stripe payment in that. So I read about webhook, what it does and integrated with my application.&lt;/p&gt;

&lt;p&gt;In this blog, I am going to cover the following things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;What is a webhook?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Webhook integration with Stripe payment intent.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. What is a WebHook?
&lt;/h2&gt;

&lt;p&gt;A WebHook is an HTTP callback: an HTTP POST that occurs when something happens. With all APIs, there’s a request followed by a response. Even for webhook, the request is made by the payment provider. just the difference is here request is initiated by another server instead of a client-side browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. WebHook integration with Stripe Payment Intent
&lt;/h2&gt;

&lt;p&gt;To use a webhook, you’ll have to register a URL with the Payment Gateway. This URL is a place within your application that will accept the data and process it. Whenever any change to your payment application happens eg: a customer creating a transfer, adding a new bank account, withdrawing funds, etc., the Payment provider will notify your application server using this webhook endpoint present in your server. It is generally a good practice to record all requests sent to this endpoint by the payment provider and process only the topics that are of application’s interests such as you may only have to process a topic &lt;em&gt;customer_bank_transfer_completed&lt;/em&gt; or &lt;em&gt;customer_bank_transfer_failed&lt;/em&gt; to mark your payment record with complete / failed.&lt;/p&gt;

&lt;p&gt;In my case, I was using the &lt;a href="https://stripe.com/docs/payments/payment-intents" rel="noopener noreferrer"&gt;Stripe payment Intent API&lt;/a&gt; and integrated the webhook for it.&lt;br&gt;
Here are the following steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a model called &lt;em&gt;Webhook&lt;/em&gt; and add attributes based on your requirements (like &lt;em&gt;event&lt;/em&gt;, &lt;em&gt;event_type&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;Create a controller called &lt;em&gt;webhook_controllers.rb&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Write an action called &lt;em&gt;create.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Add route in &lt;strong&gt;&lt;em&gt;config/routes.rb&lt;/em&gt;&lt;/strong&gt; file
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources :webhooks, only :create
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;migration&lt;/em&gt; will look like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateWebhooks &amp;lt; ActiveRecord::Migration[6.0]
  def change
    create_table :webhooks do |t|
      t.json :event
      t.string :event_type
      t.timestamps
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Paste the following code inside &lt;strong&gt;&lt;em&gt;webhook_controllers.rb&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  def create
      payload = request.body.read
      begin
        event = Stripe::Webhook.construct_event(
          payload, signature_header, endpoint_secret
        )
      rescue JSON::ParserError =&amp;gt; e
        # Invalid payload
        render json: {success: false, message: "Invalid payload"}, status: 400 and return
      rescue Stripe::SignatureVerificationError =&amp;gt; e
        # Invalid signature
        render json: {success: false, message: "Invalid signature"}, status: 400 and return
      end

json_data = JSON.parse(event.to_json)
      stripe_webhook = Webhook.create!(event: json_data, event_type: json_data["type"])
      render json: {success: true, message: "successfully stored"}, status: :ok
  end

  private

  def signature_header
     request.env['HTTP_STRIPE_SIGNATURE']
  end

  def endpoint_secret
     Rails.application.credentials.stripe.dig(:webhook_endpoint_secret)
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You will find &lt;strong&gt;endpoint_secret&lt;/strong&gt; in the stripe dashboard. First, log in to the dashboard, click on test mode then go to &lt;em&gt;Developers&lt;/em&gt; &lt;em&gt;-&amp;gt;&lt;/em&gt; &lt;em&gt;Webhooks&lt;/em&gt; &lt;em&gt;-&amp;gt;&lt;/em&gt; &lt;em&gt;signing secret&lt;/em&gt; as shown in the image. Click to reveal.&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%2Fcdn-images-1.medium.com%2Fmax%2F4432%2F1%2A5_ulFOFL9omasibboq7ayg.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%2Fcdn-images-1.medium.com%2Fmax%2F4432%2F1%2A5_ulFOFL9omasibboq7ayg.png" alt="endpoint secret image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add your endpoint to the stripe dashboard. suppose your URL is &lt;a href="https://www.mydomain.com/webhooks" rel="noopener noreferrer"&gt;https://mydomain.com/webhooks&lt;/a&gt; and select the event that you want to receive data for. You can see in the below image.&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%2Fcdn-images-1.medium.com%2Fmax%2F5912%2F1%2AbcRrEJQGfsgppuTFJ1RRgA.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%2Fcdn-images-1.medium.com%2Fmax%2F5912%2F1%2AbcRrEJQGfsgppuTFJ1RRgA.png" alt="Add Webhook endpoint image."&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%2Fcdn-images-1.medium.com%2Fmax%2F5912%2F1%2AeQfX6LC95j9KecygesdoMw.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%2Fcdn-images-1.medium.com%2Fmax%2F5912%2F1%2AeQfX6LC95j9KecygesdoMw.png" alt="selected events image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After setting up everything, you can send a test webhook and test your endpoint whether it is working perfectly or not.&lt;/p&gt;

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

&lt;p&gt;And that’s it! Did this work for you? Please leave any questions and comments below!&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

&lt;p&gt;If you found this article helpful then hit the ❤️ ❤️&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;:-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stripe.com/docs/payments/payment-intents" rel="noopener noreferrer"&gt;stripe payment intent docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stripe.com/docs/webhooks" rel="noopener noreferrer"&gt;stripe webhook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stripe.com/docs/payments/payment-intents/verifying-status#webhooks" rel="noopener noreferrer"&gt;stripe payment intent webhook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stripe.com/docs/api/events/types" rel="noopener noreferrer"&gt;types of event in stripe API&lt;/a&gt;&lt;/p&gt;

</description>
      <category>paymentgateway</category>
      <category>programming</category>
      <category>rails</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to buy SSL Certificate and Install on Server using Nginx on Ubuntu 14.04.</title>
      <dc:creator>PRADEEP KUMAR</dc:creator>
      <pubDate>Sat, 07 Aug 2021 07:10:45 +0000</pubDate>
      <link>https://dev.to/kumarpradeephk/how-to-buy-ssl-certificate-and-install-on-server-using-nginx-on-ubuntu-14-04-4p9d</link>
      <guid>https://dev.to/kumarpradeephk/how-to-buy-ssl-certificate-and-install-on-server-using-nginx-on-ubuntu-14-04-4p9d</guid>
      <description>&lt;h2&gt;
  
  
  How to buy SSL Certificate and Install on Server using Nginx on Ubuntu 14.04.
&lt;/h2&gt;

&lt;p&gt;When I was developing a Rails Application and deploying on &lt;strong&gt;DigitalOcean&lt;/strong&gt; server, had to install SSL Certificate but I had no prior knowledge how to buy SSL and install on the server but after lots of research finally, I successfully added SSL on my server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This guide will describe to you:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;i. What are the steps you have to follow to buy SSL from the domain provider.&lt;br&gt;
 ii. Install SSL certificate on the server.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;i. To buy SSL from the domain provider first you will have to generate Certificate Signing Request (CSR).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I am going to generate CSR using OpenSSL.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Steps to Proceed with:-&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Log in to your server via terminal using ssh.&lt;/p&gt;

&lt;p&gt;$ ssh &lt;a href="mailto:XYZ@xx.xx.xx.xxx"&gt;XYZ@xx.xx.xx.xxx&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It would be better to first create the directory inside /&lt;em&gt;etc&lt;/em&gt; and switch into this.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;suppose my working directory is “/etc/ssl/ssl-certs”.&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Then type the below command on the terminal and press enter.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ openssl req -new -newkey rsa:2048 -nodes -keyout mydomain.key -out mydomain.csr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Make sure to replace &lt;strong&gt;mydomain&lt;/strong&gt; with the name of your domain like mydomain.com&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;You will be prompted to answer a series of questions, explained below.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Country Name&lt;/strong&gt; — This is the two-letter abbreviation for your country. For example, the United States would be the US and Great Britain would be GB.&lt;br&gt;
 &lt;strong&gt;State or Province Name&lt;/strong&gt; — This is the full name of the state your organization operates from. For example, this might be “California” or “Michigan”.&lt;br&gt;
 &lt;strong&gt;Locality Name&lt;/strong&gt; — Name of the city your organization operates from. Examples might include “Lansing” or “Phoenix”. Don’t use abbreviations in this field. For example, “St. Helena” should be “Saint Helena”&lt;br&gt;
 &lt;strong&gt;Organization Name&lt;/strong&gt; — The name of your organization. must use your legal name.&lt;br&gt;
&lt;strong&gt;Organizational Unit Name&lt;/strong&gt; — If applying as a business, you can enter your “Doing Business As” (DBA) name here. Alternately, you can use a department name here. For example, “IT Department” or “Web Administration”.&lt;br&gt;
 &lt;strong&gt;Common Name&lt;/strong&gt; — The domain name that you are purchasing an SSL certificate for. This must be a fully qualified domain name (FQDN). An example might be mydomain.com.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;:- If you are applying for a special wildcard SSL certificate, you will need to enter an asterisk for the subdomain. An example in that case might be &lt;em&gt;**.mydomain.com&lt;/em&gt;*. Never include the “http://”, “https://”, or any other special characters in this field. Never include text after the top level domain at the end. For example, your common name should end in .com, .net, (or whatever other extension you are applying for.)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Email Address&lt;/strong&gt; — An email address that can be used as a point of contact for your domain. Be sure the address is valid!&lt;br&gt;
&lt;strong&gt;A challenge password&lt;/strong&gt; — An optional password to further secure your certificate. Be sure to remember this password if you choose to use it. It must be at least 4 characters long. You can skip this step if you like.&lt;br&gt;
 *&lt;em&gt;An optional company name *&lt;/em&gt;— Another optional step. Fill in your company name if you wish. This is not required for web SSL certificates.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y7dYGnk7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AF_Rbw6AUzOKA04iflqGieg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y7dYGnk7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AF_Rbw6AUzOKA04iflqGieg.png" alt="sample screenshot to generate CSR in Ubuntu terminal" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Yeah, Your CSR file has been generated!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To find your CSR type the following command in the current working directory.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;my current working directory is “&lt;em&gt;/etc/ssl/ssl-certs”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;/div&gt;

&lt;p&gt;then you will get two new files ending with “.csr” and “.key” respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZwvcdGxx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A3owNE0HlXIZGOydML3-1ww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZwvcdGxx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2A3owNE0HlXIZGOydML3-1ww.png" alt="" width="319" height="17"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The .key file should be kept private on your server. The .csr file is your certificate signing request and can be sent to a Certificate Authority(like GoDaddy).&lt;/p&gt;

&lt;p&gt;Now to open the &lt;em&gt;mydomain.com.csr&lt;/em&gt; file type the below command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cat *mydomain.com.csr*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and you will get below CSR generated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BlW8XYQR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AvRXtAYy6yNSquXruhk4M-Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BlW8XYQR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AvRXtAYy6yNSquXruhk4M-Q.png" alt="generated CSR" width="629" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will need to copy and paste the entire contents of the CSR file to your Certificate Authority when ordering an SSL certificate.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Be sure that you include the lines that read “BEGIN CERTIFICATE REQUEST” and “END CERTIFICATE REQUEST”.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;if you want to decode this you can &lt;a href="https://www.sslshopper.com/csr-decoder.html"&gt;visit this link&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download Certificate:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After verifying to &lt;strong&gt;GoDaddy&lt;/strong&gt; that you control the domain, check your email (the one that you registered with GoDaddy with) for a message that says that your SSL certificate has been issued. Open it, and follow the download certificate link (or click the Launch button next to your SSL certificate in the GoDaddy control panel).&lt;/p&gt;

&lt;p&gt;Now click the Download button.&lt;/p&gt;

&lt;p&gt;Select the server software that you are using from the Server type dropdown menu–if you are using Apache HTTP or Nginx, select “Nginx”–then click the Download Zip File button.&lt;/p&gt;

&lt;p&gt;Extract the ZIP archive. It should contain two .crt files; your SSL certificate (which should have a random name like &lt;strong&gt;&lt;em&gt;146b99449cc43104.crt&lt;/em&gt;&lt;/strong&gt;) and the GoDaddy intermediate certificate bundle (&lt;strong&gt;gd_bundle-g2–1.crt&lt;/strong&gt;). Copy both two your web server.&lt;/p&gt;

&lt;p&gt;So now my current working directory(“&lt;em&gt;/etc/ssl/ssl-certs&lt;/em&gt;”) has four files listed below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;***146b99449cc43104.crt *gd_bundle-g2–1.crt mydomain.com.csr mydomain.com.key**
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;The certificate is now ready to be installed on your web server. This involves adding a few SSL-related lines to your web server software configuration.&lt;br&gt;
 &lt;strong&gt;note&lt;/strong&gt;: If you have a firewall enabled, be sure that it allows port 443 (HTTPS)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here I will do Nginx configurations on Ubuntu 14.04.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;ii. Install Certificate on Server&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;you must create a single “chained” certificate file using these two files &lt;em&gt;**146b99449cc43104.crt *&lt;/em&gt;&lt;em&gt;and&lt;/em&gt;** &lt;em&gt;gd_bundle-g2–1.crt&lt;/em&gt;*&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cat 146b99459cc43104.crt gd_bundle-g2–1.crt &amp;gt; mydomain.chained.crt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now go to your Nginx server block configuration directory. Assuming that is located at &lt;strong&gt;&lt;em&gt;/etc/nginx/sites-enabled&lt;/em&gt;&lt;/strong&gt;, use this command to change to it:&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Assuming want to add SSL to your default server block file, open the file for editing:&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Find and modify the listen directive, and modify it so it looks like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;listen 443 ssl;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then find the &lt;strong&gt;server_name&lt;/strong&gt; directive, and make sure that its value matches the common name of your certificate. Also, add the &lt;strong&gt;ssl_certificate&lt;/strong&gt; and &lt;strong&gt;ssl_certificate_key&lt;/strong&gt; directives to specify the paths of your certificate and private key files&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server_name mydomain.com;
ssl_certificate /etc/ssl/*ssl-certs*/mydomain.com.chained.crt;
ssl_certificate_key /etc/ssl/*ssl-certs*/mydomain.com.key;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To allow only the most secure SSL protocols and ciphers, add the following lines to the file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
add_header Strict-Transport-Security max-age=63072000;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you want HTTP traffic to redirect to HTTPS, you can add this additional server block at the top of the file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name mydomain.com;
    return 301 https://$host$request_uri;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then save and quit.&lt;/p&gt;

&lt;p&gt;Now restart Nginx to load the new configuration and enable TLS/SSL over HTTPS!&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;Test it out by accessing your site via HTTPS, e.g. &lt;a href="https://example.com."&gt;https://mydomain.com.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;while restarting the server if you are getting fail then see the log using the following command in terminal and fix it.&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;OK, now We have nice green lock icon showing up in the web browser, but it turns out it was not enough. As I Checked with the &lt;a href="https://www.ssllabs.com/ssltest/"&gt;SSL Server Test&lt;/a&gt;, some SSL ciphers like RC4 are vulnerable, and SSL 3 is broken (my initial test score was B-…).&lt;/p&gt;

&lt;p&gt;To fix this I changed the *ssl_ciphers *like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK';/etc/ssl/ssl-certs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;My next vulnerability according to the test was my weak Diffie-Hellman keys. Diffie-Hellman key exchange is a protocol providing the pretty cool property that, even if some attackers get their hands on your server’s private key, it will be exponentially hard for them to decipher the communication between the server and its clients. However, the default key size in OpenSSL is 1024 bits, which &lt;a href="https://weakdh.org/"&gt;seems breakable&lt;/a&gt; with the computing power of a nation-state. So, you let’s generate some better parameters.&lt;/p&gt;

&lt;p&gt;First, generate your DH parameters with OpenSSL:&lt;/p&gt;

&lt;p&gt;Let's switch into the directory where .crt and .key extended files are present.&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Then run the below command to generate DH parameters. this might take a longer time.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ openssl dhparam -out dhparam.pem 4096
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Again open the server configuration file.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd /etc/nginx/sites-enabled
$ sudo vi default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and add the following line.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssl_dhparam /etc/ssl/*ssl-certs*/dhparam.pem;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now save the editor and restart the server.&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;Yeah! SSL successfully install on your server and test it out by accessing your site.*&lt;br&gt;
&lt;strong&gt;Now you check with &lt;a href="https://www.ssllabs.com/ssltest/"&gt;SSL Server Test&lt;/a&gt;.&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;&lt;em&gt;References:-&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;For Apache server go to &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-install-an-ssl-certificate-from-a-commercial-certificate-authority#prerequisites"&gt;DigitalOcean documentation&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;I&lt;a href="https://scaron.info/blog/improve-your-nginx-ssl-configuration.html"&gt;mprove SSL configuration&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;I hope, it was helpful to you. If you liked this article you are invited to leave some claps.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
