Menu

Express behind a proxy: fixing express-rate-limit when every user shares one limit
πŸ“°

Express behind a proxy: fixing express-rate-limit when every user shares one limit

DEV Community: expressΒ·SYED SHAAMEER AliΒ·16 days ago
#i6ulDGWv
#devtoexpress#devto#dev#proxy#express
Long article (1152 words) β€” no AI summary yet.
Reading 0:00
15s threshold

You add express-rate-limit, test it locally, and everything works.

Then you deploy to Render, Railway, Fly.io, or behind Nginx.

Suddenly, one of two things happens:

Your logs show ERR_ERL_UNEXPECTED_X_FORWARDED_FOR.

Your rate limiter starts treating multiple users as the same client, causing everyone to share one request limit.

The problem is often your Express proxy configuration.

When Express cannot identify the original client IP correctly, an IP-based rate limiter can end up counting requests against the proxy's address instead.

Here's why it happens, how to configure it, and what to check before deploying the fix.

Why it happens

When your Express application sits behind a reverse proxy, it doesn't communicate directly with the original client.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.