<p>I have configured nginx-ingress-controller in kubernetes and I am trying to achieve method based routing from kubernetes.</p>
<p>This is my ingress.yaml file below:</p>
<pre><code>kind: Ingress
metadata:
  name: cafe-ingress-with-annotations
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    #nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    #nginx.ingress.kubernetes.io/app-root: /
    #nginx.ingress.kubernetes.io/ssl-redirect: &quot;true&quot;
    nginx.ingress.kubernetes.io/configuration-snippet: |
      location /tea {
         limit_except GET {
            deny all;
         }
      }
spec:
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee
        backend:
          serviceName: coffee-svc
          servicePort: 80
</code></pre>
<p>according to the annotation defined it is supposed to block all other methods like POST/DELETE...etc except GET method. But it is not denying any of the methods. Please help me how can I achieve method based routing using limit_except in nginx.
Thanks in advance.</p>

<p>As you can read in <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#configuration-snippet" rel="nofollow noreferrer">here</a>, the <code>configuration-snippet</code> annotation is used for adding an additional configuration to the NGINX location.</p>
<p>If you want to add <strong>custom locations</strong> in the <code>server</code> block, you need to use <code>server-snippet</code> annotation. As you can read <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-snippet" rel="nofollow noreferrer">here</a>:</p>
<blockquote>
<p>Using the annotation <code>nginx.ingress.kubernetes.io/server-snippet</code> it is
possible to add custom configuration in the server configuration
block.</p>
</blockquote>
<p>The following <code>Ingress</code> manifest should work:</p>
<pre><code>kind: Ingress
metadata:
  name: cafe-ingress-with-annotations
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/server-snippet: |
      location /tea {
         limit_except GET {
            deny all;
         }
      }
spec:
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee
        backend:
          serviceName: coffee-svc
          servicePort: 80
</code></pre>
