<?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: Mouhamadou Tidiane Seck</title>
    <description>The latest articles on DEV Community by Mouhamadou Tidiane Seck (@moha528).</description>
    <link>https://dev.to/moha528</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%2F1092350%2F73411bd4-ea72-4948-a2c4-e941a8e6c67e.png</url>
      <title>DEV Community: Mouhamadou Tidiane Seck</title>
      <link>https://dev.to/moha528</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moha528"/>
    <language>en</language>
    <item>
      <title>How to Create a Self-Signed SSL Certificate for Nginx on Ubuntu 22.04</title>
      <dc:creator>Mouhamadou Tidiane Seck</dc:creator>
      <pubDate>Tue, 20 Aug 2024 00:00:54 +0000</pubDate>
      <link>https://dev.to/moha528/how-to-create-a-self-signed-ssl-certificate-for-nginx-on-ubuntu-2204-165j</link>
      <guid>https://dev.to/moha528/how-to-create-a-self-signed-ssl-certificate-for-nginx-on-ubuntu-2204-165j</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Securing your web server with SSL is a crucial step in protecting your users' data and ensuring the integrity of your web application. &lt;strong&gt;Let’s Encrypt&lt;/strong&gt; is a popular service that offers free SSL certificates via an automated API, with &lt;strong&gt;Certbot&lt;/strong&gt; as the most commonly used client. In this guide, we'll walk through the process of creating a self-signed SSL certificate for Nginx on Ubuntu 22.04 using Certbot.&lt;/p&gt;

&lt;p&gt;We won't delve deeply into SSL configuration, but by the end of this tutorial, you'll have a valid certificate that renews automatically. Plus, you'll know how to automate the reloading of your service to account for the renewed certificate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before starting, ensure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An Ubuntu 22.04 server with a non-root user configured with sudo privileges and a basic firewall.&lt;/li&gt;
&lt;li&gt;A domain name pointing to your server (replace &lt;code&gt;your_domain&lt;/code&gt; in the tutorial with your actual domain).&lt;/li&gt;
&lt;li&gt;Ports 80 or 443 must be free on your server. If these ports are occupied by a web server, consider using Certbot's webroot mode instead.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1 — Installing Certbot
&lt;/h2&gt;

&lt;p&gt;Certbot recommends using their snap package for installation. Snaps are supported on most Linux distributions, but you'll need &lt;code&gt;snapd&lt;/code&gt; installed to manage snap packages. Ubuntu 22.04 supports snaps by default, so start by ensuring your snapd core is up to date:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;snap &lt;span class="nb"&gt;install &lt;/span&gt;core&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;snap refresh core
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have an older version of Certbot installed, remove it:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Then, install the Certbot package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;snap &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--classic&lt;/span&gt; certbot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, link the Certbot command to your path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /snap/bin/certbot /usr/bin/certbot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Certbot is now installed, and we can proceed to obtain our SSL certificate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 — Running Certbot
&lt;/h2&gt;

&lt;p&gt;Certbot needs to respond to a cryptographic challenge issued by the &lt;strong&gt;Let’s Encrypt&lt;/strong&gt; API to prove that you control your domain. It uses ports 80 (HTTP) or 443 (HTTPS) for this purpose. Open the appropriate ports in your firewall:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 80
&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 443
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run Certbot to obtain your certificate, using the &lt;code&gt;--standalone&lt;/code&gt; option to let Certbot handle the challenge with its built-in web server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;certbot certonly &lt;span class="nt"&gt;--standalone&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; your_domain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll need to enter an email address and accept the terms of service. If successful, Certbot will inform you where the certificates are stored.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 — Configuring Your Application
&lt;/h2&gt;

&lt;p&gt;Configuring your application for SSL varies depending on the software you use, but let’s explore what Certbot has downloaded. List the directory containing your keys and certificates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo ls&lt;/span&gt; /etc/letsencrypt/live/your_domain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The most commonly needed files are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;privkey.pem&lt;/strong&gt;: This is the private key for your certificate. Keep this file secure and private.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;fullchain.pem&lt;/strong&gt;: This is your certificate bundled with any intermediate certificates. Most configurations refer to this file as the actual certificate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more details on the other files, check the Certbot documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 — Managing Automatic Renewals with Certbot
&lt;/h2&gt;

&lt;p&gt;Let’s Encrypt certificates are valid for 90 days, encouraging users to automate the renewal process. The Certbot package handles this by adding a renewal script to &lt;code&gt;/etc/cron.d&lt;/code&gt;, which runs twice daily to renew any certificates within 30 days of expiration.&lt;/p&gt;

&lt;p&gt;To automate tasks after renewal, such as reloading your server, add a &lt;code&gt;renew_hook&lt;/code&gt; to Certbot’s renewal configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/letsencrypt/renewal/your_domain.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following line to reload your services after renewal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;renew_hook &lt;span class="o"&gt;=&lt;/span&gt; systemctl reload your_service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;your_service&lt;/code&gt; with the command you need to run. Save and close the file, then perform a dry run to check for errors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;certbot renew &lt;span class="nt"&gt;--dry-run&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there are no errors, you're all set. Certbot will now automatically renew your certificate and execute the necessary commands.&lt;/p&gt;

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

&lt;p&gt;In this tutorial, we installed the &lt;strong&gt;Let’s Encrypt&lt;/strong&gt; Certbot client, obtained an SSL certificate using the standalone mode, and set up automatic renewals with custom hooks. This process provides a solid foundation for using Let’s Encrypt certificates with various services beyond the typical web server.&lt;/p&gt;




</description>
    </item>
    <item>
      <title>Configuring Nginx as a Reverse Proxy on Ubuntu 22.04</title>
      <dc:creator>Mouhamadou Tidiane Seck</dc:creator>
      <pubDate>Mon, 19 Aug 2024 23:58:16 +0000</pubDate>
      <link>https://dev.to/moha528/configuring-nginx-as-a-reverse-proxy-on-ubuntu-2204-1na3</link>
      <guid>https://dev.to/moha528/configuring-nginx-as-a-reverse-proxy-on-ubuntu-2204-1na3</guid>
      <description>&lt;p&gt;A &lt;strong&gt;reverse proxy&lt;/strong&gt; is a server that sits between client devices and backend servers, forwarding client requests to the appropriate server. &lt;strong&gt;Nginx&lt;/strong&gt; is commonly used as a reverse proxy due to its stability, simple configuration, and low resource consumption. In this guide, we'll walk through how to configure Nginx as a reverse proxy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Network Architecture
&lt;/h2&gt;

&lt;p&gt;A reverse proxy typically has at least two network interfaces:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;External Interface&lt;/strong&gt;: This interface is exposed to the internet and handles requests from external users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Internal Interface&lt;/strong&gt;: This interface communicates with the backend web servers that hold the requested information.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s a diagram illustrating the basic flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;External Users -&amp;gt; Reverse Proxy (Nginx) -&amp;gt; Internal Web Servers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Roles and Benefits of a Reverse Proxy
&lt;/h2&gt;

&lt;p&gt;Using a reverse proxy like Nginx offers several advantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Load Balancing&lt;/strong&gt;: Distributes incoming traffic across multiple web servers, improving performance and availability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Traffic Management&lt;/strong&gt;: Allows you to manage server maintenance or migrations without downtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Centralized Configuration&lt;/strong&gt;: Manages access and configuration for multiple sites and web servers from a single location.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Traffic Optimization&lt;/strong&gt;: Uses caching and compression to improve response times.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced Security&lt;/strong&gt;: Handles SSL encryption and filters requests/URLs to increase security.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Configuring Nginx as a Reverse Proxy
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1 — Installing Nginx
&lt;/h3&gt;

&lt;p&gt;Start by installing Nginx on your server:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update the package index:
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install Nginx:
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Ensure Nginx is running:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  systemctl status nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2 — Configuring the Firewall (Optional)
&lt;/h3&gt;

&lt;p&gt;If your server’s firewall is active, you'll need to allow HTTP traffic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allow HTTP traffic:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow &lt;span class="s1"&gt;'Nginx HTTP'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3 — Creating a Configuration File
&lt;/h3&gt;

&lt;p&gt;Create a configuration file for your site:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a text editor like &lt;code&gt;nano&lt;/code&gt; to create a new configuration file in the &lt;code&gt;/etc/nginx/sites-available/&lt;/code&gt; directory:
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4 — Configuring the Server Block
&lt;/h3&gt;

&lt;p&gt;Edit the server block configuration with your domain and application server address:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Insert the following configuration into your new file, replacing &lt;code&gt;your_domain&lt;/code&gt; and &lt;code&gt;app_server_address&lt;/code&gt; with your actual domain and server address:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  server &lt;span class="o"&gt;{&lt;/span&gt;
      listen 80&lt;span class="p"&gt;;&lt;/span&gt;
      listen &lt;span class="o"&gt;[&lt;/span&gt;::]:80&lt;span class="p"&gt;;&lt;/span&gt;

      server_name your_domain www.your_domain&lt;span class="p"&gt;;&lt;/span&gt;

      location / &lt;span class="o"&gt;{&lt;/span&gt;
          proxy_pass http://app_server_address&lt;span class="p"&gt;;&lt;/span&gt;
          include proxy_params&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5 — Activating the Configuration
&lt;/h3&gt;

&lt;p&gt;Activate the new configuration file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a symbolic link from the configuration file to the directory that Nginx reads from at startup:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;sudo ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6 — Testing the Configuration
&lt;/h3&gt;

&lt;p&gt;Test the Nginx configuration for syntax errors and then restart Nginx:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verify the configuration:
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Restart Nginx to apply the changes:
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Optional: Using Gunicorn
&lt;/h3&gt;

&lt;p&gt;If you need to run a Python web application, you can use Gunicorn as an application server:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Gunicorn:
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a test application that returns "Hello World!" in an HTTP response to verify Gunicorn is working correctly.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;You have successfully configured Nginx as a reverse proxy for your websites. This setup not only optimizes traffic management but also enhances the security and scalability of your web infrastructure. Feel free to explore more Nginx features to further improve your deployment!&lt;/p&gt;




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