<p>i am running an Nginx ingress controller and wanted to allow only few path for users to connect and rest all I wanted to  block or provide an 403 error. how can i do that?</p>
<p>I only wanted users to allow to connect <code>/example</code> and  rest all should be  blocked.</p>
<pre><code>kind: Ingress
metadata:
  name: ingress1
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: ingress.example.com
    http:
      paths:
      - path: /example
        backend:
          serviceName: ingress-svc
          servicePort: 80
</code></pre>
<p>Can i add a nginx server-snippet?</p>
<pre><code>     location path {
       &quot;if the path is not matching then deny&quot;
       deny all;
     }```
</code></pre>

akhinair
<p>Make a custom backend using below</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: custom-http-backend
spec:
  selector:
    matchLabels:
      app: custom-http-backend
  template:
    metadata:
      labels:
        app: custom-http-backend
    spec:
      containers:
      - name: custom-http-backend
        image: inanimate/echo-server
        ports:
        - name: http
          containerPort: 8080
        imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
  name: custom-http-backend
spec:
  selector:
    app: custom-http-backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
</code></pre>
<p>Then in your ingress add this rule</p>
<pre><code>- host: ingress.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: custom-http-backend
          servicePort: 80
</code></pre>
