<?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: Rodolphe Beloncle</title>
    <description>The latest articles on DEV Community by Rodolphe Beloncle (@rodolphebeloncle).</description>
    <link>https://dev.to/rodolphebeloncle</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%2F1513878%2F6ecb5388-0a47-4529-a813-e853969d8596.jpeg</url>
      <title>DEV Community: Rodolphe Beloncle</title>
      <link>https://dev.to/rodolphebeloncle</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rodolphebeloncle"/>
    <language>en</language>
    <item>
      <title>Deploy secured HTTPS web server on Ubuntu OS with Let's Encrypt behind a home router</title>
      <dc:creator>Rodolphe Beloncle</dc:creator>
      <pubDate>Wed, 22 May 2024 07:11:33 +0000</pubDate>
      <link>https://dev.to/rodolphebeloncle/deploy-secured-https-web-serveur-on-ubuntu-os-with-lets-encrypt-behind-a-home-router-5b8a</link>
      <guid>https://dev.to/rodolphebeloncle/deploy-secured-https-web-serveur-on-ubuntu-os-with-lets-encrypt-behind-a-home-router-5b8a</guid>
      <description>&lt;p&gt;How to Deploy a Simple Secured HTTPS Website on Ubuntu with Let's Encrypt and DuckDNS&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;A computer running Ubuntu.&lt;/li&gt;
&lt;li&gt;Access to your home router to open ports.&lt;/li&gt;
&lt;li&gt;A DuckDNS domain name.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Create a DuckDNS Domain Name
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Visit &lt;a href="https://www.duckdns.org/"&gt;DuckDNS&lt;/a&gt; and create an account.&lt;/li&gt;
&lt;li&gt;Create a new subdomain and assign it to your router's external IP address.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 2: Configure Your Home Router
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open the router settings page (usually available at &lt;code&gt;192.168.1.1&lt;/code&gt; or &lt;code&gt;192.168.0.1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Forward the following ports to your Ubuntu machine’s internal IP address:

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Port 80 (HTTP)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port 443 (HTTPS)&lt;/strong&gt;
In my case it's a orange wifi box &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;If you've got a orange box follow this link :&lt;br&gt;
&lt;a href="https://assistance.orange.fr/livebox-modem/toutes-les-livebox-et-modems/installer-et-utiliser/piloter-et-parametrer-votre-materiel/le-parametrage-avance-reseau-nat-pat-ip/configurer-des-regles-nat-pat/livebox-6-et-7-configurer-les-regles-nat-pour-pouvoir-utiliser-certains-jeux-ou-applications-serveur_362613-896058"&gt;How to configure nat rules for applications server&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Check Your External IP Address
&lt;/h2&gt;

&lt;p&gt;Visit &lt;a href="https://mon-ip.info/"&gt;mon-ip.info&lt;/a&gt; to verify your external IP address.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Configure Firewall
&lt;/h2&gt;

&lt;p&gt;Open your terminal and run the following commands to configure the 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 &lt;span class="nb"&gt;enable
sudo &lt;/span&gt;ufw status verbose
&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 80/tcp
&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 443/tcp
&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw reload
&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 5: Install Nginx&lt;/p&gt;

&lt;p&gt;Install Nginx if it's not already installed:&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 update
&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;p&gt;Step 6: Create Nginx Configuration for Your Domain&lt;/p&gt;

&lt;p&gt;Create an Nginx configuration file for your DuckDNS domain:&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/nginx/sites-available/mydomainename.duckdns.org
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following configuration:&lt;br&gt;
&lt;/p&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;
    server_name mydomainename.duckdns.org www.mydomainename.duckdns.org&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;301 https://&lt;span class="nv"&gt;$host$request_uri&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

server &lt;span class="o"&gt;{&lt;/span&gt;
    listen 443 ssl&lt;span class="p"&gt;;&lt;/span&gt;
    server_name mydomainename.duckdns.org www.mydomainename.duckdns.org&lt;span class="p"&gt;;&lt;/span&gt;

    ssl_certificate /etc/letsencrypt/live/mydomainename.duckdns.org/fullchain.pem&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_certificate_key /etc/letsencrypt/live/mydomainename.duckdns.org/privkey.pem&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_protocols TLSv1.2 TLSv1.3&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_prefer_server_ciphers on&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_ciphers EECDH+AESGCM:EDH+AESGCM&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_ecdh_curve secp384r1&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_session_cache shared:SSL:10m&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_session_timeout 10m&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_stapling on&lt;span class="p"&gt;;&lt;/span&gt;
    ssl_stapling_verify on&lt;span class="p"&gt;;&lt;/span&gt;
    resolver 8.8.8.8 8.8.4.4 &lt;span class="nv"&gt;valid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;300s&lt;span class="p"&gt;;&lt;/span&gt;
    resolver_timeout 5s&lt;span class="p"&gt;;&lt;/span&gt;

    add_header Strict-Transport-Security &lt;span class="s2"&gt;"max-age=63072000; includeSubdomains; preload"&lt;/span&gt; always&lt;span class="p"&gt;;&lt;/span&gt;
    add_header X-Frame-Options DENY&lt;span class="p"&gt;;&lt;/span&gt;
    add_header X-Content-Type-Options nosniff&lt;span class="p"&gt;;&lt;/span&gt;

    location / &lt;span class="o"&gt;{&lt;/span&gt;
        try_files &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;/ &lt;span class="o"&gt;=&lt;/span&gt;404&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;p&gt;Step 7: Enable Your Nginx Configuration&lt;/p&gt;

&lt;p&gt;Create a symbolic link to enable the site:&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; /etc/nginx/sites-available/mydomainename.duckdns.org /etc/nginx/sites-enabled/

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

&lt;/div&gt;



&lt;p&gt;Test the Nginx configuration and restart Nginx:&lt;br&gt;
sudo nginx -t&lt;br&gt;
sudo systemctl restart nginx&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;nginx &lt;span class="nt"&gt;-t&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart nginx

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

&lt;/div&gt;



&lt;p&gt;Step 8: Obtain SSL Certificate with Let's Encrypt&lt;/p&gt;

&lt;p&gt;Install Certbot and the Nginx plugin:&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 update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;certbot python3-certbot-nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generate the SSL certificate:&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 &lt;span class="nt"&gt;--nginx&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; mydomainename.duckdns.org &lt;span class="nt"&gt;-d&lt;/span&gt; www.mydomainename.duckdns.org
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 9: Verify and Reload Nginx&lt;/p&gt;

&lt;p&gt;!!! Verify that the generated Let's Encrypt certificate has the same name as in your Nginx config. &lt;/p&gt;

&lt;p&gt;Follow the prompts to complete the certificate&lt;/p&gt;

&lt;p&gt;Reload Nginx to apply the new 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;systemctl reload nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your secured HTTPS website should now be live and accessible via your DuckDNS domain name.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nginx</category>
    </item>
  </channel>
</rss>
