🚫 Block VPNs, Tor & Proxies with Nginx using MyIP.casa (in 5 minutes)

🛡️ Security  ·  Nginx  ·  5 min guide

🚫 Block VPNs, Tor & Proxies with Nginx using MyIP.casa

📅 March 28, 2026  ·  ~5 min read

Allowing only "clean" users on your infrastructure is a real challenge. Whether you're trying to prevent spam, fraud, or large-scale scraping, filtering traffic from VPNs, proxies, or datacenter IPs is your first line of defense.

In this guide, you'll learn how to integrate the MyIP.casa API directly into your Nginx configuration to block unwanted traffic in minutes.


1

🔧 Understanding auth_request

Nginx provides a powerful module called ngx_http_auth_request_module. It allows you to send a subrequest to an internal API before granting access to your application.

✅  If the API returns 200 → access is allowed
❌  If the API returns 403 → access is denied

This makes it perfect for real-time IP filtering.


2

🧠 Create a filtering microservice

Since you already have access to MyIP.casa Pro, you can build a simple endpoint that checks whether an IP is a VPN or not.

● ● ●   Python / Flask
@app.route("/check-access")
def check_access():
    ip = request.headers.get("X-Real-IP")

    # Query MyIP.casa intelligence (or your cache)
    is_vpn = get_vpn_status(ip)

    if is_vpn:
        return "Forbidden", 403
    return "OK", 200
In production, you should:
•  Cache results (Redis recommended)
•  Avoid calling the API on every request

3

⚙️ Configure Nginx

Add the following to your Nginx site file (e.g. /etc/nginx/sites-available/default):

● ● ●   Nginx — sites-available/default
server {
    listen 80;
    server_name your-site.com;

    location / {
        auth_request /validate-ip;
        proxy_pass http://your_real_backend;
    }

    location = /validate-ip {
        internal;
        proxy_pass https://your-internal-api/check-access;
        proxy_pass_request_body off;
        proxy_set_header Content-Length "";
        proxy_set_header X-Real-IP $remote_addr;
    }

    error_page 403 = @blocked;
    location @blocked {
        return 403 "Access denied: VPN/proxy not allowed.";
    }
}

4

⚡ Why caching is critical

Querying an API on every HTTP request will slow down your application. Cache the decision for 24 hours using:

• Redis  • In-memory cache  • lua_shared_dict (OpenResty)

🚀 Better performance 💰 Lower API usage 🔒 Stable security

✅ Conclusion

By combining the accuracy of MyIP.casa Pro with the flexibility of Nginx, you can enforce perimeter security automatically without impacting legitimate users. It's fast, scalable, and production-ready.


💡 Pro tip — Start with a trial key and upgrade to Pro when ready to deploy at scale.
● ● ●   cURL
curl -H "X-API-Key: YOUR_API_KEY" https://myip.casa/api/pro/details

🚀 Start filtering VPNs in minutes

Get your free API key and secure your infrastructure today.

Get API Key →

Commentaires

Posts les plus consultés de ce blog

Check Open Ports Instantly (No CLI Required)

🔎 SSL Certificate Decoder: How to Read and Analyze Any Certificate