最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to exclude http requests for static files from nginx rate limiting - Stack Overflow

programmeradmin2浏览0评论

I'm using below nginx block. I want to exclude all requests for js and CSS files from nginx rate limiting. With my below nginx directives, rate limiting is excluded to all files apart from /api route. How to fix it? I want to only exclude js & css files from rate limiting. My nginx version is nginx/1.18.0 (Ubuntu).

limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=1r/s;

server {
    # other server directives...

    # Location block for JavaScript files (no rate limiting)
    location ~* \.(js|css)$ {
        # No limit_req here, so no rate limiting applies
    }

    # General location block with rate limiting for other requests
    location / {
        limit_req zone=req_limit_per_ip burst=5 nodelay;  # Rate limit applied here
    }

    location /api {
        limit_req zone=req_limit_per_ip burst=5 nodelay;  # Rate limit applied here
     }
}
发布评论

评论列表(0)

  1. 暂无评论