<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nensi Gjata on Medium]]></title>
        <description><![CDATA[Stories by Nensi Gjata on Medium]]></description>
        <link>https://medium.com/@nensi601?source=rss-1461bd87da6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*26LM1Dh3Mji8N8TA</url>
            <title>Stories by Nensi Gjata on Medium</title>
            <link>https://medium.com/@nensi601?source=rss-1461bd87da6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 21:57:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nensi601/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[CSS: Macro Categories of Properties]]></title>
            <link>https://medium.com/@nensi601/css-macro-categories-of-properties-8c7732df0944?source=rss-1461bd87da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c7732df0944</guid>
            <category><![CDATA[category]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Nensi Gjata]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 10:56:18 GMT</pubDate>
            <atom:updated>2025-04-17T10:56:18.624Z</atom:updated>
            <content:encoded><![CDATA[<p>While teaching a web development course recently, I found myself reflecting on how to explain CSS more effectively. Most tutorials focus on individual properties, detailing their specific functions. While this approach is informative, it can often overwhelm beginners who are trying to see the bigger picture.</p><p>To provide a clearer understanding, I’ve tried to categorise CSS properties into macro groups based on their functionality. I hope this approach can offer a new perspective, making it easier to grasp and apply CSS in real-world scenarios.</p><figure><img alt="CSS: Macro Categories of Properties" src="https://cdn-images-1.medium.com/max/1024/1*1boJX51LLLO3p7ucSs48hA.png" /></figure><blockquote>I won’t dive into the details of every single property and how it’s used — otherwise, this article would turn into a full-blown book. 😅</blockquote><blockquote>Instead, for each macro category, I’ll include a link to resources that offer a deeper, more technical explanation of the properties involved. That way, if you’re curious or need a refresher, you can explore further at your own pace.</blockquote><h3>📦 1. Box Model</h3><p>The <strong>Box Model</strong> defines the space around and inside HTML elements, including borders and how size is calculated. It’s at the heart of how elements are rendered and spaced on the page.</p><pre>margin<br>padding<br>border, border-radius<br>box-sizing<br>width, height, min-width, max-height<br>...</pre><p>While width and height are fairly self-explanatory, understanding the full CSS box model—especially the distinction between margin and padding—is crucial for building clean, consistent layouts.</p><p>🔗 Want to dive deeper? <a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model">Here’s a detailed guide to the CSS Box Model</a>.</p><h3>🧱 2. Layout</h3><p>The <strong>Layout</strong> category includes CSS properties that define how elements are structured and positioned within the page. Whether you’re building a simple component or architecting a full-blown responsive UI, these properties are essential.</p><pre>display<br>position, top, right, bottom, left<br>float, clear<br>z-index<br>flex, grid, gap, place-items, align-self<br>overflow, visibility​​ <br>...</pre><p>I would like to highlight the most commonly used properties — but in this case, <strong>all of these are extensively used</strong> in real-world CSS. Together, they form the foundation of how web layouts are built today.</p><h3>🔤 3. Typography</h3><p>These are some of the most common CSS properties used to control the <strong>appearance, spacing, and layout of text</strong>. Typography has a major impact on both readability and visual hierarchy, so it’s an essential part of styling any web page.</p><pre>font-family, font-size, font-weight, font-style<br>line-height, letter-spacing, word-spacing<br>text-align, text-transform, text-decoration<br>white-space<br>...</pre><blockquote><em>🎯 If I had to pick just three, the most commonly used would be </em><strong><em>text-align</em></strong><em>, </em><strong><em>font-size</em></strong><em>, and </em><strong><em>font-weight</em></strong><em>—but truth be told, </em><strong><em>most of these get used regularly</em></strong><em> in real-world projects.</em></blockquote><p>🔗 For a more detailed look at each of these properties, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Typography">check out this comprehensive typography guide</a>.</p><h3>🎨 4. Color &amp; Background</h3><p>The <strong>Color &amp; Background</strong> category controls the visual aesthetics of elements by managing colors, images, and transparency.</p><pre>color<br>background-color, background-image, background-size, background-position<br>opacity<br>...</pre><blockquote><em>🎯 The most commonly used here are </em><strong><em>color</em></strong><em> and </em><strong><em>background</em></strong><em> properties. These are fundamental in web design for creating contrast and adding visual appeal.</em></blockquote><p>🔗 For a deeper dive into color and background properties, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Backgrounds_and_Borders">check out this article</a>.</p><h3>✨ 5. Visual Effects</h3><p>The <strong>Visual Effects</strong> category adds aesthetic enhancements to elements, such as shadows, filters, and blending effects, that give your design depth and style.</p><pre>box-shadow, text-shadow<br>filter, backdrop-filter<br>mix-blend-mode<br>...</pre><blockquote><em>🎯 Choosing the most widely used here is simpler: </em><strong><em>box-shadow</em></strong><em> is by far the most popular. While the others—</em><strong><em>filter</em></strong><em>, </em><strong><em>backdrop-filter</em></strong><em>, and </em><strong><em>mix-blend-mode</em></strong><em>—are used less frequently, they’re still important to understand for advanced design work.</em></blockquote><p>🔗 For more details, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/filter">check out this article on Visual Effects</a>, and if you want some cool shadow examples to inspire your designs, take a look here.</p><h3>🎞️ 6. Transitions &amp; Animations</h3><p>The <strong>Transitions &amp; Animations</strong> category contains properties used to create motion and dynamic behaviour for page elements, bringing your website to life with smooth changes and interactive effects.</p><pre>transition, transition-duration, transition-timing-function<br>animation, @keyframes, animation-name, animation-duration​</pre><blockquote><em>🎯 These properties help make web pages feel interactive and responsive, elevating the user experience with subtle motions and transitions.</em></blockquote><p>🔗 To explore these properties in greater detail, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions">check out this comprehensive guide</a> and for some really cool animation examples, <a href="https://github.com/animate-css/animate.css">this animation library</a> is one of the best to explore.</p><h3>🔄 7. Transforms &amp; 3D</h3><p>The <strong>Transforms &amp; 3D</strong> category is used to apply transformations to elements, such as rotating, scaling, and even changing the perspective in 3D space. These properties bring dynamic motion and depth to your designs.</p><pre>transform (e.g., rotate, scale, translate)<br>transform-origin<br>perspective, backface-visibility</pre><blockquote><em>🎯 While these properties might seem advanced, they’re incredibly powerful. If I had to choose the most widely used, it would be the </em><strong><em>transform</em></strong><em> property. But as always, all of these properties are crucial for creating sophisticated 3D and animated effects.</em></blockquote><p>🔗 To dive deeper, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transform">check out this detailed guide</a> on transforms and 3D properties.</p><h3>📐 8. Flexbox &amp; Grid</h3><p>The <strong>Flexbox &amp; Grid</strong> category is essential for creating complex page layouts. Whether you’re building entire page structures or just small components, these properties make layout creation intuitive and responsive.</p><pre>flex, flex-grow, flex-shrink, flex-basis<br>justify-content, align-items, align-content<br>grid-template-columns, grid-area</pre><blockquote><em>🎯 </em><strong><em>Flexbox</em></strong><em> and </em><strong><em>Grid</em></strong><em> are must-know properties when it comes to modern web design. They make creating responsive layouts and even small widgets much easier and more flexible.</em></blockquote><p>🔗 To master Flexbox and Grid layouts, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout">check out this detailed guide</a> on both techniques.</p><h3>📱 9. Responsive &amp; Media</h3><p>The <strong>Responsive &amp; Media</strong> category is all about making your web pages adapt to different screen sizes and containers, ensuring a smooth experience across devices, from desktops to mobile phones.</p><pre>@media queries<br>clamp(), min(), max() functions<br>container-type, container-name</pre><blockquote><em>🎯 The </em><strong><em>@media</em></strong><em> query is by far the most commonly used property here, enabling responsive design. But the others, like </em><strong><em>clamp()</em></strong><em> and </em><strong><em>min()/</em></strong><strong><em>max()</em></strong><em>, are extremely valuable for modern, fluid layouts.</em></blockquote><p>🔗 To learn more about these properties and how to use them effectively, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries">check out this guide</a>.</p><h3>🖱️ 10. Interactivity &amp; Accessibility</h3><p>The <strong>Interactivity &amp; Accessibility</strong> category focuses on improving how users interact with a website and ensuring that your web content is accessible to everyone, including people with disabilities.</p><pre>cursor<br>pointer-events<br>user-select<br>tab-index</pre><blockquote><em>🎯 The most commonly used property in everyday life is maybe </em><strong><em>cursor</em></strong><em>, but accessibility is a broad and critical topic. It’s essential to ensure that your website is usable for all users.</em></blockquote><p>🔗 For a more detailed explanation of accessibility and interactivity, <a href="https://developer.mozilla.org/en-US/docs/Learn/Accessibility">check out this comprehensive article</a>.</p><h3>🗂️ 11. Tables &amp; Lists</h3><p>The <strong>Tables &amp; Lists</strong> category deals with styling and customizing the appearance of tables and list elements, ensuring they look good and are easy to read.</p><pre>border-collapse, table-layout<br>list-style, list-style-type, list-style-position</pre><blockquote><em>🎯 These properties are essential for working with tables and lists, which are crucial elements for organizing content on a page.</em></blockquote><p>🔗 For an in-depth explanation of how HTML tables work and the most important CSS properties that can be applied to them, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table">check out this detailed guide</a>.</p><h3>Final Thoughts</h3><p>By grouping CSS properties into macro categories, we can start to understand CSS as a system rather than a random collection of rules. This approach not only helps you organize your stylesheets but also makes it easier to learn and apply best practices.</p><p>While these categories cover the most essential and commonly used CSS properties, it’s important to remember that there are many more properties in CSS than the ones mentioned here. As CSS evolves, new properties and features are introduced to improve functionality and address new design challenges, so continuous learning and exploration are key to mastering CSS.</p><blockquote>Any feedback — whether it’s suggestions for adding more properties, refining or merging the categories, or pointing out errors — is greatly appreciated. Let’s work together to enhance our understanding of CSS and make this resource even better!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c7732df0944" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Publishing a Website with Caddy on Ubuntu]]></title>
            <link>https://medium.com/@nensi601/publishing-a-website-with-caddy-on-ubuntu-9ad710879842?source=rss-1461bd87da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ad710879842</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[caddy]]></category>
            <category><![CDATA[website-development]]></category>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Nensi Gjata]]></dc:creator>
            <pubDate>Thu, 10 Apr 2025 13:29:53 GMT</pubDate>
            <atom:updated>2025-04-10T13:40:27.332Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*btXoSLwe2UMwbk3jCj376Q.png" /></figure><p>In this tutorial, we’ll see how to serve web pages on Ubuntu (Linux) using <strong>Caddy</strong> as a web server, either to serve static pages or to proxy PHP requests.</p><p>We’ll cover two use cases:</p><ol><li><strong>Static website</strong> — Map requests directly to HTML files. In this case, you don’t need a backend language. Caddy will simply serve your HTML, JavaScript, and CSS files.</li><li><strong>Dynamic PHP application</strong> — Proxy requests to a PHP server. Caddy will handle incoming requests, forward them to PHP, and serve the processed responses to clients.</li></ol><p>The first step, of course, is to install the Caddy web server.</p><h3><strong>Installing Caddy:</strong></h3><p>Caddy can be installed in different ways, but here we’ll use the simplest method recommended in the official Caddy documentation.</p><p>First, update your package list and install the necessary dependencies:</p><pre>sudo apt update<br>sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl</pre><p>Next, add Caddy’s GPG key and repository:</p><pre>curl -1sLf &#39;https://dl.cloudsmith.io/public/caddy/stable/gpg.key&#39; | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg<br>curl -1sLf &#39;https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt&#39; | sudo tee /etc/apt/sources.list.d/caddy-stable.list</pre><p>Update the package list again and install Caddy:</p><pre>sudo apt update<br>sudo apt install caddy</pre><p>You can always refer to the official installation guide for more details: <a href="https://caddyserver.com/docs/install">Caddy Installation Docs</a></p><p>After installation, check if Caddy is running by using:</p><pre>sudo systemctl status caddy</pre><p>If everything went well, you should see that Caddy is active and running!</p><h3>Optional: Configuring UFW (Firewall)</h3><p>This step depends on whether you’re using a firewall on your system. If you’re using a different firewall, please refer to its specific documentation.</p><p>On <strong>Ubuntu Server</strong>, the default firewall is <strong>UFW (Uncomplicated Firewall)</strong>. I’ll quickly show you how to open the necessary ports for Caddy.</p><h4>Step 1: Check if UFW is installed and active</h4><p>Run the following command:</p><pre>sudo ufw status verbose</pre><ul><li>If the output shows Status: inactive, it means there’s no active firewall. <em>(For security purposes, I recommend setting one up eventually.)</em></li><li>If you see Status: active, continue to the next step.</li></ul><h4>Step 2: Open the HTTP and HTTPS ports</h4><p>Allow traffic on ports <strong>80</strong> (HTTP) and <strong>443</strong> (HTTPS) with the following command:</p><pre>sudo ufw allow proto tcp from any to any port 80,443<br>sudo ufw reload</pre><p>Then reload UFW to apply the changes:</p><pre>sudo ufw reload</pre><p>With these rules, you’re telling the firewall to allow web traffic to your server.</p><h3>Checking Caddy installation</h3><p>Now, with Caddy installed and the firewall configured, you can open your browser and navigate to your server’s IP or domain name. You should see the default Caddy welcome page, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cO2ipX115Tl4SEqp3jKnuA.png" /><figcaption>Caddy Default Page</figcaption></figure><p>Congratulations — if you’ve reached this point, Caddy is running correctly! <br>Now, let’s tell Caddy where to find your website files.</p><h3>Configuring Your Website Location</h3><h4>Step 1: Create the website directory</h4><p>First, create a directory to store your website files. We’ll use /var/www, which is a common location for web files.</p><p>Run these commands:</p><pre># Create the directory<br>sudo mkdir -p /var/www<br><br># Assign ownership to the www-data user (Caddy runs as this user)<br>sudo chown -R www-data:www-data /var/www<br><br># Set appropriate permissions (read and execute, no write for others)<br>sudo chmod -R 755 /var/www</pre><h4>Step 2: Configure Caddy to serve your website</h4><p>Now, we’ll edit the Caddy configuration file to point to this directory.</p><p>Open the Caddy file with:</p><pre>cd /etc/caddy<br>sudo nano Caddyfile</pre><p>Replace the content of the file with the following configuration (make sure to update domain_name.aaa with your actual domain!):</p><pre>domain_name.aaa {<br>  root * /var/www<br>  encode zstd gzip<br><br>  @dotFiles {<br>    path */.*<br>    not path /.well-known/*<br>  }<br><br>  file_server<br><br>  log {<br>    level INFO<br>    output file /var/log/caddy/domain_name.log {<br>      roll_size 10MiB<br>      roll_keep 10<br>      roll_keep_for 336h<br>    }<br>  }<br>}</pre><h4>Explanation:</h4><ul><li><strong>root</strong>: Specifies the directory containing your website files.</li><li><strong>encode</strong>: Enables compression for faster load times.</li><li><strong>@dotFiles</strong>: Denies access to hidden files (like .env), but allows access to the /.well-known/ directory (useful for SSL certificate challenges).</li><li><strong>file_server</strong>: Enables static file serving.</li><li><strong>log</strong>: Configures logging so you can monitor your web server activity.</li></ul><p>You can save the file using: Ctrl + O, Enter, then Ctrl + X to exit.</p><h4>Step 3: Validate and apply your configuration</h4><p>Before applying your changes, it’s a good idea to validate the Caddy configuration to catch any mistakes.</p><p>Run:</p><pre>sudo caddy validate --config /etc/caddy/Caddyfile</pre><p>If there are no errors, you’re ready to apply the configuration!</p><p>You have two options:</p><ol><li><strong>Reload the entire Caddy service (safe and recommended):</strong></li></ol><pre>sudo systemctl reload caddy</pre><p>2. <strong>Alternatively, reload just the configuration without restarting the whole service:</strong></p><pre>sudo caddy reload</pre><p>Both commands will apply your changes, but the second option is faster if you’re already actively working on the server.</p><h3>Setting Up the Website Files</h3><p>In the /var/www directory, you can upload your website files. By default, Caddy will look for an index.html file if no specific filename is provided in the browser’s address bar.</p><p>Once you’ve uploaded your files to /var/www, Caddy will start serving them automatically. If you make any changes to the files, simply refresh your browser to see the updates immediately.</p><h3>Installing PHP and Configuring Caddy as a Proxy</h3><p>If you want to serve a full-fledged web application using PHP, you’ll need to configure Caddy to proxy requests to the PHP server and return the response to the browser.</p><h4>Step 1: Install PHP</h4><p>To install PHP 8.4 (or another version, if needed), run the following commands:</p><pre># Install PHP and essential extensions<br>sudo apt install php8.4<br>sudo apt install php8.4-common php8.4-fpm php8.4-curl php8.4-mysql php8.4-gd php8.4-mbstring php8.4-zip php8.4-xml php8.4-bcmath</pre><p>This will install the PHP server along with useful extensions to handle MySQL database connections, create ZIP files, and more. Feel free to add other extensions based on your specific use case.</p><h4>Step 2: Configure Caddy to Proxy Requests to PHP</h4><p>After installing PHP, you need to configure Caddy to forward PHP requests to the PHP server. Edit your Caddy file with the following configuration:</p><pre>domain_name.aaa {<br>  root * /var/www<br>  encode zstd gzip<br>  php_fastcgi unix//run/php/php-fpm.sock<br><br>  # Other configuration...<br>  # same as before<br>}</pre><h4>Step 3: Validate and Apply Caddy Configuration</h4><p>As with previous changes, validate the configuration to ensure everything is correct:</p><pre>sudo caddy validate --config /etc/caddy/Caddyfile</pre><p>If no errors are shown, apply the changes by running:</p><pre>sudo caddy reload</pre><p>If there are errors, correct them before re-running the reload command.</p><h4>Step 4: Test the PHP Server</h4><p>Now that PHP is configured, let’s test it by creating a simple PHP file to ensure everything is working.</p><p>Create a new file called test.php in the /var/www folder with the following content:</p><pre>&lt;?php<br>phpinfo();<br>?&gt;</pre><p>You can create this file using nano:</p><pre>cd /var/www<br>sudo nano test.php</pre><p>Paste the code and then press Ctrl + X to save and exit.</p><p>Alternatively, you can use the following command to create the file in one go:</p><pre>echo &#39;&lt;?php phpinfo(); ?&gt;&#39; | sudo tee /var/www/test.php &gt; /dev/null &amp;&amp; sudo chown www-data:www-data /var/www/test.php &amp;&amp; sudo chmod 644 /var/www/test.php &amp;&amp; echo &quot;test.php created at /var/www/test.php&quot;</pre><h4>Step 5: Access the PHP Test Page</h4><p>Now, open your browser and navigate to:<em> </em><a href="https://my_domain.aaa/test.php"><em>https://my_domain.aaa/test.php</em></a></p><p>(Replace my_domain.aaa with your actual domain name.)</p><p>If everything is working correctly, you should see a PHP info page showing the PHP configuration.</p><p>and you should see in the browser a similar page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kCTDIXxun1hzwJ66Xddkeg.png" /><figcaption>PHP8.4 phpinfo() rendered page</figcaption></figure><h3>Conclusion</h3><p>Now that everything is set up, you can install any PHP application you want, and Caddy will handle the rest — from serving static files to proxying requests to PHP.</p><p>Thank you for reading, and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ad710879842" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proxied and Containerized Keycloak Instance]]></title>
            <link>https://medium.com/@nensi601/proxied-and-containerized-keycloak-instance-192624aa8364?source=rss-1461bd87da6------2</link>
            <guid isPermaLink="false">https://medium.com/p/192624aa8364</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[caddy]]></category>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Nensi Gjata]]></dc:creator>
            <pubDate>Fri, 19 Jul 2024 14:29:55 GMT</pubDate>
            <atom:updated>2024-07-19T14:29:55.751Z</atom:updated>
            <content:encoded><![CDATA[<h4>Configuring a Keycloak Instance on a Linux Node Using Docker Compose and Exposing It with a Caddy Reverse Proxy</h4><blockquote>Hi everyone, it’s been a while that I wanted to write this article but only now I’m finding the time to do so. Now I’m retaking my notes and I’m trying to describe a little better what I did so if anyone needs it they can find it here.</blockquote><blockquote>A little introduction:</blockquote><blockquote>I have some running services in a cloud server and things are installed using the following principle: If needed always, install it natively. If it is something temporary, use Docker.</blockquote><blockquote>In this server, I like to expose the services using Caddy as a reverse proxy so I can expose everything through HTTPS. If I want to know what is exposed, I just look at the Caddy file. To be a little bit safer, I have protected everything through a firewall, and the only open ports are HTTP, HTTPS, and SSH (small advice: change the default ssh port if you don’t want to find gigabytes of wrong logins in the logs). On my DNS zone, I can expose each service on a domain/subdomain. I’m happy and everything works as well as it can…</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SENnosNrQ02pOYYu0hzV_g.jpeg" /></figure><p>Some days ago I had to make some tests with Keycloak so I wanted to add the service to my server. And here our journey begins …</p><h4><strong>1. KeyCloak Configuration</strong></h4><p>A Keycloak server can be run on Docker and needs a backing database. I have Docker on my machine and I have a natively installed Postgres database.</p><blockquote><strong>Warning:</strong> If you’re using UFW as a firewall, don’t blindly expose Docker ports. It appears that UFW does not have control over Docker’s publicly exposed ports. There are many guides online that explain why and provide solutions. I won’t go into details here, but the message is: please be careful.</blockquote><p>The problem is: How can I access the native Postgres from inside the Docker container? It turns out this can be done very conveniently using the following line (at least in ubuntu):</p><pre>extra_hosts:<br>      - &quot;host.docker.internal:host-gateway&quot;</pre><p>After adding this line in the Docker Compose service, if you want to access the host IP from inside the container, you just use the following DNS name: host.docker.internal.</p><p>With this resolved, we can create the Keycloak instance very quickly using the following docker-compose.yml file:</p><pre>keycloak:<br>    image: quay.io/keycloak/keycloak:25.0<br>    hostname: keycloak<br>    container_name: keycloak<br>    extra_hosts:<br>      - &quot;host.docker.internal:host-gateway&quot;<br>    command: start<br>    environment:<br>      KC_HOSTNAME: &quot;[exposed_hostname]&quot;<br>      KC_HOSTNAME_PORT: 8080<br>      KC_HTTP_ENABLED: &quot;true&quot;<br>      KC_HOSTNAME_STRICT_BACKCHANNEL: &quot;false&quot;<br>      KC_HOSTNAME_STRICT_HTTPS: &quot;false&quot;<br>      KC_HEALTH_ENABLED: &quot;true&quot;<br>      KEYCLOAK_ADMIN: *********************<br>      KEYCLOAK_ADMIN_PASSWORD: *********************<br>      KC_DB: postgres<br>      KC_DB_URL: jdbc:postgresql://host.docker.internal:5432/[db_name]?schema=[db_schema]]<br>      KC_DB_USERNAME: ********************<br>      KC_DB_PASSWORD: *********************<br>      KC_HOSTNAME_URL: &quot;[web endpoint hostname]&quot;<br>      KC_HOSTNAME_ADMIN_URL: &quot;[web endpoint hostname]&quot;<br>      KC_PROXY: &quot;edge&quot;<br>      PROXY_ADDRESS_FORWARDING: &quot;true&quot;<br>  <br>    ports:<br>      - &quot;8081:8080&quot;<br>    restart: unless-stopped</pre><p>where:</p><ul><li>exposed_hostname: is the name of the host machine that is publicly exposed.</li><li>db_name / db_schema: is the name of the database and schema where Keycloak will connect.</li><li>KC_HOSTNAME_URL, KC_HOSTNAME_ADMIN_URL: should contain the public address of your server.</li><li>KC_PROXY and PROXY_ADDRESS_FORWARDING: configure Keycloak to interpret correctly the proxy forwarded requests.</li></ul><p>Now set your configurations, and to run it, just go to the docker-compose.yml folder and execute:</p><pre>docker-compose keycloak up</pre><p>You should see in the logs that everything starts up correctly.</p><blockquote>If something goes wrong, it’s probably the URL or credentials because that’s the only thing we have configured manually here).</blockquote><p><strong>Note: </strong>If you encounter any problems with the authentication but everything seems right, check the PostgreSQL pg_hba.conf file. The file is usually located in:</p><pre>sudo nano /etc/postgresql/[postgress_version]/main/pg_hba.conf</pre><p><em>It should contain a line like the following:</em></p><pre>#Note: The 172.0.0.0/8 is the subnet usually used by docker. <br>#      Here i have authorized the logins of this username (role)<br>#      if the request comes from/to the docker network<br><br>host keycloak keycloak 172.0.0.0/8  scram-sha-256</pre><p>If there are no problems, stop the container using:</p><pre>docker-compose stop keycloak</pre><p>and follow on with the reverse proxy configuration.</p><h4>2. Caddy Configuration</h4><p>Caddy is one of the best web servers I’ve seen. I don’t have words to describe the appreciation, so I’ll leave you with the script that configures the reverse proxy for the Keycloak instance::</p><pre>#use your configured port in [port]<br><br>exposed_hostname {<br> reverse_proxy http://127.0.0.1:[port]<br> log {<br>  level INFO<br>  output file /var/log/caddy/keycloak.log {<br>   roll_size 10MiB<br>   roll_keep 10<br>   roll_keep_for 336h<br>  }<br> }<br>}</pre><p>Just save these lines inside a file called Caddyfile, usually located in:</p><pre>#If you have ubuntu and installed caddy using apt<br><br>/etc/caddy/Caddyfile</pre><p>then just:</p><pre>#Edit the Caddyfile<br><br>sudo nano /etc/caddy/Caddyfile</pre><p>then just:</p><pre>cd /etc/caddy<br>sudo caddy reload</pre><p>Once reloaded, you should be able to access your Keycloak instance by navigating to your endpoint in a browser. If everything is configured correctly, you will see the Keycloak login page.</p><p>Hope this helps someone :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=192624aa8364" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>