<p>I have an ingress something like below</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: staging-ingress-rules-login
  annotations:
    kubernetes.io/ingress.class: 'nginx'
    nginx.ingress.kubernetes.io/proxy-body-size: '0'
spec:
  rules:
  - host: staging.mysite.com
    http:
      paths:
      - path: /
        backend:
          serviceName: login
          servicePort: 80
      - path: /login/info
        backend:
          serviceName: login
          servicePort: 80
</code></pre>
<p>and the nginx.conf for this is something like this</p>
<pre><code>server { 
 location / {
   ---------
   ---------
}

location /login/info {
  ---------
  -------
}

} 
</code></pre>
<p>I would like to add the rate limit for location /login.info, i tried location-snippet but it is creating nested location inside /login/info and the result for this api is giving 404, any way to do this ?</p>

<p>This is a community wiki answer, feel free to edit and expand it.</p>
<p>As we are lacking some details regarding your configuration, I will explain how you can deal with this in general.</p>
<p>You can use the below annotation in order to add a custom location block:</p>
<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
  limit_req zone=authentication_ratelimit nodelay;
</code></pre>
<p>And than use a <strong>map</strong>, for example:</p>
<pre><code>http-snippets: |
  map $uri $with_limit_req {
    default 0;
    &quot;~*^/authenticate$&quot; 1;
  }
  map $with_limit_req $auth_limit_req_key {
    default '';
    '1'     $binary_remote_addr; # the limit key
  }
  limit_req_zone $auth_limit_req_key zone=authentication_ratelimit:10m rate=1r/s;
</code></pre>
<p><a href="http://nginx.org/en/docs/http/ngx_http_limit_req_module.html#limit_req_zone" rel="nofollow noreferrer">Notice that</a>:</p>
<blockquote>
<pre><code>Syntax:   limit_req_zone key zone=name:size rate=rate [sync];
Default:  —
Context:  http
</code></pre>
<p>Sets parameters for a shared memory zone that will keep states for
various keys. In particular, the state stores the current number of
excessive requests. The key can contain text, variables, and their
combination. Requests with an empty key value are not accounted.</p>
</blockquote>
