---
title: "Discussion on \"Handling Geographical Cache Using Nginx and Lua\" | Hashnode"
description: "Discussion on \"Handling Geographical Cache Using Nginx and Lua\". The following approach uses Nginx to serve the user already cached data based on their geographical location.\nAssume we have an application, which gets the latitude and the longitude of the user, searches through a database which in this sample appli..."
url: "https://hashnode.com/posts/handling-geographical-cache-using-nginx-and-lua/60203b1a636acc2a3823035a"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Handling Geographical Cache Using Nginx and Lua](https://ehsanfa.hashnode.dev/handling-geographical-cache-using-nginx-and-lua?utm_source=hashnode&utm_medium=feed)

The following approach uses Nginx to serve the user already cached data based on their geographical location. Assume we have an application, which gets the latitude and the longitude of the user, searches through a database which in this sample appli...

Feb 7, 2021 · 6 min read · ehsanfa.hashnode.dev  
Read the article

-   [#nginx](https://hashnode.com/tag/nginx)
-   [#lua](https://hashnode.com/tag/lua)
-   [#redis](https://hashnode.com/tag/redis)
-   [#geospatial](https://hashnode.com/tag/geospatial)
-   [#flask](https://hashnode.com/tag/flask)

## Written by

[Ehsan Fazeli](https://hashnode.com/@ehsanfa)

@ehsanfa · Darmstadt, Germany

  
[View profile](https://hashnode.com/@ehsanfa)

Software Engineer

## Responses 1

Markdown supported · ⌘↵ to post

[CDN Edge Ops](https://hashnode.com/@cdnedgeops)

[Nov 9](https://hashnode.com/posts/handling-geographical-cache-using-nginx-and-lua/60203b1a636acc2a3823035a/comment/6af235a1a1bd141a01e3e63c)

Geographical cache with Lua only helps when the region discriminator that picks the upstream also enters the cache key. If the key stays on scheme, Host, and path alone while Lua chooses a regional origin, you can serve region-A bytes from a region-B fill and never notice until currency, licensing, or language diverges. Fold a normalized region token into the key or bypass cache on personalized paths, keep short validity for HTML shells, and expose upstream cache status so HIT, MISS, and BYPASS stay visible without packet captures.

Ops prove-out after enabling the geo map: hit the same URI from two synthetic region inputs and confirm both cache status and upstream address diverge as designed. After a quiet period, watch inactive eviction — a cold region looks like a geo miss when the slab is simply empty. Log upstream address with cache status for a week before widening TTL, and deny Set-Cookie or Authorization from poisoning the shared zone.
