<p>I'm trying to filter out all paths that begin with <code>/something</code>. While the regex seems PCRE valid by online testers, the result is <code>404</code> for all paths:</p>

<pre class="lang-json prettyprint-override"><code>kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: myhost.com
    http:
      paths:
      - backend:
          serviceName: myservice
          servicePort: 80          
        path: /^([^something].*)
</code></pre>

<p>Tried to play with the regex (e.g, <code>path: /(^[^something])(.*)</code>), but still get <code>404</code> for all.</p>

<p>What am I missing?</p>

<p>Using <code>v1.12.2</code> client with <code>v1.14.1</code> server.</p>

Kludge
<p>If you want to deny all traffic to <code>/something</code> you should use <code>Nginx</code> annotations called <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-snippet" rel="nofollow noreferrer">server-snipped</a>. It will allow you to add custom configuration.</p>

<p>It would look like:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
   name: nginx-snippet
   annotations:
      nginx.ingress.kubernetes.io/configuration-snippet: |

      location /something {

           deny all;  
      }
</code></pre>

<p>Fimilar example can be found on <a href="https://github.com/nginxinc/kubernetes-ingress/issues/161#issuecomment-322224255" rel="nofollow noreferrer">Github</a> thread.</p>

<p>You can also consider second option with 2 <code>ingress</code> objects and <code>authentication</code>. This was mentioned in another <a href="https://stackoverflow.com/a/51894604/11148139">StackOverflow question</a>.</p>

<p>In addition, you can deny access not only by location but also with specific IP. It can be obtain using annotation called <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#whitelist-source-range" rel="nofollow noreferrer">whitelist-source-range</a>.</p>
