NGX
413
MB
Nginx Upload
413 • body size • proxy

Nginx 413 after client_max_body_size: how to fix it

Why Nginx still returns 413 even after setting client_max_body_size, and how to fix it when you have multiple proxy or reverse proxy layers.

5 min read20/05/2026

Root cause

HTTP 413 "Request Entity Too Large" is thrown when the request body exceeds the configured limit. In a multi-layer stack (CDN → Nginx → App), any layer can return 413, so you need to find which one is actually blocking you.

Fix in Nginx

# nginx.conf or inside a server block
http {
    client_max_body_size 100M;  # default is 1M

    server {
        # Can also be set at server or location level
        location /upload {
            client_max_body_size 500M;
        }
    }
}
nginx -t && nginx -s reload

Fix in the upstream app

If Nginx is fine but you still get 413, check the application:

NestJS / Express:

// main.ts
app.use(express.json({ limit: '100mb' }));
app.use(express.urlencoded({ limit: '100mb', extended: true }));

NestJS with @nestjs/platform-fastify:

const app = await NestFactory.create<NestFastifyApplication>(
  AppModule,
  new FastifyAdapter({
    bodyLimit: 104857600, // 100MB in bytes
  }),
);

Debugging a multi-layer proxy

Check the response headers to identify which layer is returning 413:

curl -v -X POST https://api.example.com/upload \
  -H "Content-Type: application/json" \
  -d '{"data": "..."}' 2>&1 | grep -E "(< HTTP|< Server|< X-)"

# < HTTP/2 413
# < server: cloudflare    ← Cloudflare is blocking, not Nginx!

If the server header says cloudflare, raise the limit in Cloudflare:

  • Cloudflare → Rules → Configuration Rules → Request Body Size
  • Free plan default: 100 MB, Enterprise: unlimited
# If server header is nginx
# < server: nginx
# → Fix in nginx config

# If no server header or it shows the app framework
# → Fix at the application layer