<p>I have Sentry running in my cluster and i want to expose it on subpath using nginx ingress but it seems that it only works on root path, i tried several ways but it didn't work. Is there any configuration i can perform in order to make it work on a subpath because i've seen some examples using these two variables in the sentry.conf.py file:</p>

<p><strong>SENTRY_URL_PREFIX = '/sentry'<br>
FORCE_SCRIPT_NAME = '/sentry'</strong></p>

<p>But i don't know if it works</p>

<p>Here is the ingress resource for sentry :</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: "sentry-ingress"
  namespace: "tools"
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
  labels:
    app: sentry-ingress
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: "sentry"
              servicePort: 9000
</code></pre>

touati ahmed
<p>Your ingress does not work properly.</p>

<p>In <a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/" rel="nofollow noreferrer">nginx ingress docs</a> you can read:</p>

<blockquote>
  <p><strong>IMPORTANT NOTES</strong>:
  If the <code>use-regex</code> OR <code>rewrite-target</code> annotation is used on any Ingress for a given host, then the case insensitive regular expression <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#location" rel="nofollow noreferrer">location modifier</a> will be enforced on ALL paths for a given host regardless of what Ingress they are defined on.</p>
</blockquote>

<p>Meaning that when you use rewrite-target annotation, <code>path</code> field value is treated as regexp and not as a prefix. This is why <code>path: /</code> is matched literally and only with <code>/</code>. </p>

<p>So if you want to use rewrite-target you should do it as following:</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: sentry-ingress
  namespace: tools
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  labels:
    app: sentry-ingress
spec:
  rules:
    - http:
        paths:
          - path: /sentry/(.*)
            backend:
              serviceName: sentry
              servicePort: 9000
</code></pre>
