<?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[Raw Logs]]></title><description><![CDATA[Unfiltered thoughts on code, math, and modern thinking — from a developer who loves to build and question.]]></description><link>https://blogs.haripatel.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1753379462235/95fc4552-3c3d-4876-b811-832487bd7152.png</url><title>Raw Logs</title><link>https://blogs.haripatel.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 06:03:13 GMT</lastBuildDate><atom:link href="https://blogs.haripatel.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Implementing Geo-Fencing with NGINX Reverse Proxy]]></title><description><![CDATA[In many cases, we need to restrict access to our web applications or services based on the location of the user. This is usually done to follow security policies, regional regulations, or vendor requirements.
Some teams use third-party services like ...]]></description><link>https://blogs.haripatel.dev/implementing-geo-fencing-with-nginx-reverse-proxy</link><guid isPermaLink="true">https://blogs.haripatel.dev/implementing-geo-fencing-with-nginx-reverse-proxy</guid><category><![CDATA[nginx]]></category><category><![CDATA[Devops]]></category><category><![CDATA[geofencing]]></category><category><![CDATA[Reverse Proxy]]></category><category><![CDATA[Linux]]></category><dc:creator><![CDATA[Hari Patel]]></dc:creator><pubDate>Sun, 03 Aug 2025 10:46:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/f5pTwLHCsAg/upload/c7d806a76c7a47e067142d363f003072.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In many cases, we need to restrict access to our web applications or services based on the location of the user. This is usually done to follow security policies, regional regulations, or vendor requirements.</p>
<p>Some teams use third-party services like Cloudflare for this purpose, since they provide built-in geo-fencing features. But that also means routing all traffic through their servers, which can affect performance in production environments.</p>
<p>If you're already using a reverse proxy like NGINX or Apache, you can set up geo-fencing on your own without needing third-party services. This approach gives you more control, eliminates external dependencies, and allows you to log and analyze traffic according to your preferences.</p>
<p>In this blog, I’ll walk through how I set up geo-fencing using NGINX and a GeoIP2 database on a self-hosted Ubuntu server.</p>
<h2 id="heading-requirements">Requirements</h2>
<ul>
<li><p>Ubuntu server</p>
</li>
<li><p>NGINX</p>
</li>
<li><p>GeoIP2 database (from <a target="_blank" href="http://ipinfo.io">IPInfo</a>)</p>
<h2 id="heading-step-1-install-nginx-and-required-packages">Step 1: Install NGINX and Required Packages</h2>
<p>  First, make sure NGINX is installed. Then install the required modules and tools:</p>
<pre><code class="lang-bash">  sudo apt update
  sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin nginx-module-geoip2 -y
</code></pre>
<h2 id="heading-step-2-enable-the-geoip2-module-in-nginx">Step 2: Enable the GeoIP2 Module in NGINX</h2>
<p>  Edit the main NGINX config file:</p>
<pre><code class="lang-bash">  sudo nano /etc/nginx/nginx.conf
</code></pre>
<p>  At the top of the file, load the geoip2 module:</p>
<pre><code class="lang-bash">  load_module modules/ngx_http_geoip2_module.so;

  http {
      ...
  }
</code></pre>
<hr />
<h2 id="heading-step-3-download-the-geoip-database">Step 3: Download the GeoIP Database</h2>
<p>  We'll use IPInfo’s GeoIP2-compatible database here. Create a folder for it:</p>
<pre><code class="lang-bash">  sudo mkdir -p /etc/nginx/geoip
  <span class="hljs-built_in">cd</span> /etc/nginx/geoip
</code></pre>
<p>  Download the database (replace <code>{Token}</code> with your actual token from <a target="_blank" href="http://ipinfo.io">ipinfo.io</a>):</p>
<pre><code class="lang-bash">  wget <span class="hljs-string">"https://ipinfo.io/data/ipinfo_lite.mmdb?token={Token}"</span> -O ipinfo_lite.mmdb
</code></pre>
<hr />
<h2 id="heading-step-4-configure-geoip2-in-nginx">Step 4: Configure GeoIP2 in NGINX</h2>
<p>  Now we’ll configure NGINX to use this database and block access based on country.</p>
<p>  In your server or site config:</p>
<pre><code class="lang-bash">  http {

      geoip2 /etc/nginx/geoip/ipinfo_lite.mmdb {
          auto_reload 5m;
          <span class="hljs-variable">$ipinfo_country_code</span> default=IN <span class="hljs-built_in">source</span>=<span class="hljs-variable">$remote_addr</span> country_code;
      }

      map <span class="hljs-variable">$ipinfo_country_code</span> <span class="hljs-variable">$allow</span> {
          default no;
          IN yes;  <span class="hljs-comment"># Allow only India (IN)</span>
      }
  }
</code></pre>
<p>  Edit in domain config</p>
<pre><code class="lang-bash">  server {
      ... 
      location / {   
          <span class="hljs-keyword">if</span> (<span class="hljs-variable">$allow</span> != yes) {
              <span class="hljs-built_in">return</span> 403;
          }
      }
  }
</code></pre>
<p>  This setup blocks all countries except India. You can adjust the country code as per your needs.</p>
<hr />
<h2 id="heading-step-5-add-logging-for-analysis">Step 5: Add Logging for Analysis</h2>
<p>  For debugging or analytics, it helps to log request info in a structured format. Add this to your NGINX config:</p>
<pre><code class="lang-bash">
  log_format geo_csv <span class="hljs-string">'"$remote_addr","$ipinfo_country_code","$time_local","$request_method","$host","$request_uri","$allow_country","$body_bytes_sent","$http_user_agent"'</span>;
  access_log /var/<span class="hljs-built_in">log</span>/nginx/geo_access.log geo_csv;
</code></pre>
<p>  This will create logs that you can easily analyze or import into tools like Excel or ELK Stack.</p>
<hr />
<h2 id="heading-step-6-reload-nginx">Step 6: Reload NGINX</h2>
<p>  After all changes are done, test your config and reload:</p>
<pre><code class="lang-bash">  sudo nginx -t
  sudo systemctl reload nginx
</code></pre>
<hr />
<h2 id="heading-wrap-up">Wrap-up</h2>
<p>  That’s it. You now have a basic geo-fencing setup running on your own infrastructure using NGINX. No need to rely on external services like Cloudflare.</p>
<p>  This setup is ideal if:</p>
<ul>
<li><p>You want full control over traffic.</p>
</li>
<li><p>You don’t want to route requests through third-party proxies.</p>
</li>
<li><p>You need detailed logs for auditing or analytics.</p>
</li>
</ul>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[RabbitMQ Simplified: Understanding Messaging Queues]]></title><description><![CDATA[How it works

Applications]]></description><link>https://blogs.haripatel.dev/rabbitmq-simplified-understanding-messaging-queues</link><guid isPermaLink="true">https://blogs.haripatel.dev/rabbitmq-simplified-understanding-messaging-queues</guid><category><![CDATA[rabbitmq]]></category><category><![CDATA[message queue]]></category><category><![CDATA[Queues]]></category><dc:creator><![CDATA[Hari Patel]]></dc:creator><pubDate>Sun, 23 Feb 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/dIaQX8L77S8/upload/543c899faf2db5c691e638aaf336fa1d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-how-it-works">How it works</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753377083754/51df24a2-8204-4bd2-a0af-76eb215e8afb.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-applications">Applications</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753377104769/a692a75c-999f-4ee2-8f95-7092754ae78d.png" alt class="image--center mx-auto" /></p>
]]></content:encoded></item></channel></rss>