‹ Goodness Duru

TILS


Nginx Geo

Jul 30, 2026

I am a big fan of making my applications as light as possible and that means taking advantage of their service dependencies. For me, that looks like pushing as much data handling as possible to the database (usually Postgres) and letting the reverse proxy (usually Nginx) handle whatever network tasks it can. I read this article on fake Googlebots and I was curious about how to use Nginx to block them. In the old days, I’d search Google, but now I use Gemini and its ilk and here’s Gemini’s answer:

# 1. Map Google's official IP ranges (populated via script/cron)
geo $is_real_googlebot {
    default 0;
    include /etc/nginx/googlebot-ips.conf; # Contains ranges like 66.249.66.0/24 1;
}

# 2. Check if the User-Agent claims to be Googlebot
map $http_user_agent $claims_googlebot {
    default 0;
    "~*Googlebot" 1;
}

# 3. Combine checks: Claims Googlebot AND NOT in Google IP list
map "$claims_googlebot:$is_real_googlebot" $fake_googlebot {
    "1:0" 1;
    default 0;
}

server {
    ...
    if ($fake_googlebot) {
        return 403; # Or 444 to close connection without response
    }
}

What caught my attention was the keyword geo. This is an Nginx directive that lets you define variables based on the client IP addresses. These variables let you take actions such as showing certain pages to certain clients, adding headers, or blocking traffic from specific networks in subsequent config blocks. The possibilities are endless.

Anyway, I thought I’d share this.

Localhost Tunneling

Jan 30, 2025

I learned this because of an error. I assumed I couldn’t use http://localhost:[port-no] as a redirect URL when testing the app on my machine. I’m ashamed to say that even though I have written two articles on OAuth, I assumed something wrong. Thankfully, I gained new knowledge something for my error.

Before I corrected myself, I was using localhost.run. Using it requires SSH reverse tunnels. Localhost.run is a good service, but it caused a bug in my app. I needed an alternative.

It turns out that you can run SSH localhost tunneling on your computer. All you need to get a publicly accessible web application running on localhost is a server that is reachable from the Internet via SSH and a domain name/subdomain. Thankfully I had both! All I needed to do was set nginx reverse proxy on my server for the domain name to a particular port number (let’s say 20001) like this

server_name subdomain.domain.com;
.....other lines....
location / {
      proxy_pass http://127.0.0.1:20001;                                        # use a port that you like. 30000 is a good one.
    }
......other lines....

On my computer, I just needed to run ssh -N -T -R 20001:localhost:3000 user@my-machine -i /path/to/keys(my web app is running on port 3000). Like magic, it worked! As a bonus, I added TLS with Let’s Encrypt.

Alex Le’s article was a great help and I encourage you to read it.

Mozilla/5.0

Jan 01, 2025

While reading access logs of my web server, I noticed that almost all browsers’ user agent output started with Mozilla/5.0. I found that curious and decided to dive into the reason why.

It turns out that Gecko, the Firefox rendering engine started it. This was okay because that was Mozilla. Web developers liked Gecko and gave the good website code to it. When KHTML was created for Konqueror, they wanted some of that good code and added Mozilla/5.0 to its user agent string. Apple forked KHTML to create Webkit (Safari and old Chrome) and carried on the tradition. Google continued the tradition when they forked Webkit to create Blink (new Chrome and Edge).

It was interesting following the story. Just a series of newer browser engines seeking acceptance.

Tensor Cores

Dec 31, 2024

I had always thought that the difference between high end CPUs vs GPUs were between 3x to 20x. It turns out that I was totally wrong. Modern GPUs can have up to 100x better performance than CPUs on Machine Learning workloads. This is because of Tensor Cores.

Tensor Cores are parts of the GPUs that specialize in Fused-Multiply Add operations (a*b + c). These operations are common in Machine learning workloads.

I had always wondered why the idea of using lots of CPUs to replace GPUs in ML training and inference isn’t widely used considering the price differences. It turns out Tensor Cores are a big part of that.

Hugo Github

Nov 26, 2024

I finally deployed this Hugo based site on Github. It was surprisingly easy. All I had to do was follow the instruction on the Hugo website.

Adding a custom domain was easy too. You can’t go wrong following this Github documentation.

« Older posts Newer posts »