<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Secure Nginx With Let&#x27;s Encrypt]]></title><description><![CDATA[<p dir="auto">Securing your Nginx server with a free SSL certificate from Let's Encrypt is a great step to ensure your website traffic is encrypted and secure. We will use <strong>Certbot</strong>, the officially recommended tool by the Electronic Frontier Foundation (EFF), to automate the issuance and installation process.</p>
<p dir="auto">Here is a complete step-by-step guide. This guide assumes you are using <strong>Ubuntu</strong> or <strong>Debian</strong>, which are the most common distributions for this setup.</p>
<p dir="auto"><strong>Prerequisites</strong></p>
<p dir="auto">Before you begin, ensure you have:</p>
<ol>
<li><strong>An Nginx server</strong> installed and running.</li>
<li><strong>A registered domain name</strong> (e.g., <a href="http://example.com" rel="nofollow ugc">example.com</a>).</li>
<li><strong>DNS Records configured</strong>: Your domain's A record must point to your server's public IP address.</li>
<li><strong>Root or sudo access</strong> to your server.</li>
</ol>
<h2>Step 1: Configure the Nginx Server Block</h2>
<p dir="auto">Certbot is smart enough to find your Nginx configuration and automatically inject the SSL settings, but only if your <code>server_name</code> directive is set correctly.</p>
<ul>
<li>
<p dir="auto">Open your Nginx configuration file for your site. Depending on your OS, this is typically located in <code>/etc/nginx/sites-available/example.com</code> or <code>/etc/nginx/conf.d/example.com.conf</code>.</p>
</li>
<li>
<p dir="auto">Ensure the <code>server_name</code> explicitly lists the domains you want certificates for.</p>
</li>
</ul>
<p dir="auto">Here is a minimal example of what that server block should look like before Certbot touches it:</p>
<pre><code>server {
    listen 80;
    listen [::]:80;
    
    # Certbot looks for this line to know which file to update
    server_name example.com www.example.com; 

    root /var/www/yourdomain.com/html;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
}
</code></pre>
<ul>
<li>After verifying or making any changes, always test your Nginx config for syntax errors:</li>
</ul>
<pre><code>sudo nginx -t
</code></pre>
<ul>
<li>If the test is successful, reload Nginx to apply the changes:</li>
</ul>
<pre><code>sudo systemctl reload nginx
</code></pre>
<h2>Step 2: Install Certbot</h2>
<p dir="auto">I will walk you through the official installation method recommended by the Electronic Frontier Foundation (the creators of Let's Encrypt).</p>
<p dir="auto">They recommend using <strong>Snap</strong> to install Certbot. This method ensures you always have the latest, most secure version of Certbot, and it works universally across almost all modern Linux distributions (Ubuntu, Debian, etc.).</p>
<ol>
<li>Ensure <strong>Snap</strong> is Installed and Updated :</li>
</ol>
<pre><code>sudo snap install core
sudo snap refresh core
</code></pre>
<ol start="2">
<li>Remove Old Versions of Certbot (If Applicable)<br />
If you previously tried to install or had an older version of Certbot, you should remove it before going any further to prevent conflicts.</li>
</ol>
<pre><code>sudo apt-get remove certbot
</code></pre>
<ol start="3">
<li>Now, install the Certbot package itself using Snap. The <code>--classic</code> flag is required because Certbot needs broader system access to read and modify your Nginx configuration files.</li>
</ol>
<pre><code>sudo snap install --classic certbot
</code></pre>
<ol start="4">
<li>Next, create a symbolic link so you can easily run the certbot command from anywhere in your terminal:</li>
</ol>
<pre><code>sudo ln -s /snap/bin/certbot /usr/bin/certbot
</code></pre>
<h2>Step 3: Allow HTTPS Through the Firewall</h2>
<p dir="auto">If you have the Uncomplicated Firewall (ufw) enabled, you need to allow HTTPS traffic.</p>
<p dir="auto">Check the current status:</p>
<pre><code>sudo ufw status
</code></pre>
<p dir="auto">It will probably look like this, meaning that only HTTP traffic is allowed to the web server :</p>
<pre><code>OutputStatus: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
Nginx HTTP                 ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
Nginx HTTP (v6)            ALLOW       Anywhere (v6)
</code></pre>
<p dir="auto">Allow Nginx Full (which covers both HTTP on port 80 and HTTPS on port 443) and delete the redundant Nginx HTTP profile allowance :</p>
<pre><code>sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP'
</code></pre>
<p dir="auto">Your status should now look like this :</p>
<pre><code>sudo ufw status
</code></pre>
<pre><code>OutputStatus: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)
</code></pre>
<h2>Step 4: Obtain and Install the SSL Certificate</h2>
<p dir="auto">Now, run <code>certbot</code> with the <code>--nginx</code> plugin. This will automatically obtain the certificate and modify your Nginx configuration to serve it.</p>
<p dir="auto">Run the following command, using <code>-d</code> to specify the domain names we’d like the certificate to be valid for,  replacing those domain names with your own:</p>
<pre><code>sudo certbot --nginx -d example.com -d www.example.com
</code></pre>
<p dir="auto">During the setup, Certbot will ask you a few questions:</p>
<ul>
<li>Enter an email address (used for urgent renewal and security notices).</li>
<li>Agree to the Terms of Service.</li>
<li>Choose whether or not you want to share your email with the Electronic Frontier Foundation (EFF).</li>
</ul>
<p dir="auto">After going through the above process, you should see a message confirming that it was successful. This message will also indicate where your certificates are stored:</p>
<pre><code>OutputIMPORTANT NOTES:
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/your_domain/fullchain.pem
Key is saved at: /etc/letsencrypt/live/your_domain/privkey.pem
This certificate expires on 2022-06-01.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
</code></pre>
<p dir="auto">Once completed, Certbot will download the certificate, apply it to your Nginx configuration, and automatically set up redirects so all HTTP traffic is forced to HTTPS. You can now visit <strong><a href="https://example.com" rel="nofollow ugc">https://example.com</a> (replace with your own domain)</strong> in your browser and notice your browser’s security indicator. It should indicate that the site is properly secured, usually with the secure padlock icon.</p>
<h2>Step 5: Verify Certificate Auto-Renewal</h2>
<p dir="auto">Let's Encrypt certificates are only valid for 90 days. Fortunately, the Certbot snap package automatically creates a <code>systemd</code> timer that runs twice a day to renew any certificate within 30 days of expiration.</p>
<p dir="auto">You can check the status of this background timer with :</p>
<pre><code>sudo systemctl status snap.certbot.renew.service
</code></pre>
<p dir="auto">and see the output :</p>
<pre><code>Output○ snap.certbot.renew.service - Service for snap application certbot.renew
     Loaded: loaded (/etc/systemd/system/snap.certbot.renew.service; static)
     Active: inactive (dead)
TriggeredBy: ● snap.certbot.renew.timer
</code></pre>
<p dir="auto">To guarantee that the automated renewal process will work when the time comes, you can safely simulate a renewal by running a dry run:</p>
<pre><code>sudo certbot renew --dry-run
</code></pre>
<p dir="auto">If you see no errors, you are all set! Certbot will handle the updates and seamlessly reload Nginx in the background before your certificates expire.</p>
]]></description><link>https://ivan9.com/topic/4/secure-nginx-with-let-s-encrypt</link><generator>RSS for Node</generator><lastBuildDate>Mon, 04 May 2026 01:38:18 GMT</lastBuildDate><atom:link href="https://ivan9.com/topic/4.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 22 Mar 2026 07:46:27 GMT</pubDate><ttl>60</ttl></channel></rss>