Adding HTTP Rate Limits in Nginx example for Parse

Step 1

sudo su -
vi /etc/nginx/conf.d/yourconfig.conf

step 2
limit_conn_zone $binary_remote_addr zone=concurrent:10m;
limit_req_zone $binary_remote_addr zone=somefunction:10m rate=1r/s;
# you don't need this first line bit below, i'm just showing where to put this in nginx config
server {

       location /parse/functions/somefunction {
                limit_req zone=somefunction burst=5 nodelay;
                limit_conn concurrent 1;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:1337/parse/functions/sendGift;
                proxy_ssl_session_reuse off;
                proxy_set_header Host $http_host;
                proxy_redirect off;
        }

# you don't need this bit, i'm just showing where to put this in nginx config
}
nginx -t
service nginx restart

Leave a Reply

Your email address will not be published. Required fields are marked *