<p>I have following ingress.yaml</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
    name: nginx-configuration-snippet
    annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /$2
        nginx.ingress.kubernetes.io/server-snippet: |
          location /base/path/v1/api/update {
              deny all;
              return 404;
            }
spec:
  rules:
    - http:
        paths:
          - path: /base/path(/|$)(.*)
            backend:
              serviceName: myApi
              servicePort: 8080
</code></pre>
<p>But when I send PUT request to /base/path/v1/api/update instead of getting 404 I am getting 500 which means that the path is reachable from ingress controller. Can anybody help me identify why ?</p>
<p>I changed to configuration-snippet and the error I got is :</p>
<pre><code>Error: exit status 1
2020/08/06 18:35:07 [emerg] 1734#1734: location &quot;/base/path/v1/api/update&quot; is outside location &quot;^/base/path(/|$)(.*)&quot; in /tmp/nginx-cfg008325631:2445
nginx: [emerg] location &quot;/base/path/v1/api/update&quot; is outside location &quot;^/base/path(/|$)(.*)&quot; in /tmp/nginx-cfg008325631:2445
nginx: configuration file /tmp/nginx-cfg008325631 test failed
</code></pre>

<p>Adding my own answer :
The final config that worked for me was :</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
    name: nginx-configuration-snippet
    annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /$2
        nginx.ingress.kubernetes.io/server-snippet: |
          location ~* &quot;^/base/path/v1/api/update&quot; {
              deny all;
              return 403;
            }
spec:
  rules:
    - http:
        paths:
          - path: /base/path(/|$)(.*)
            backend:
              serviceName: myApi
              servicePort: 8080
</code></pre>
