How to expose sentry on subpath in nginx ingress?

倖福魔咒の 提交于 2021-01-29 09:47:26

问题


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:

SENTRY_URL_PREFIX = '/sentry'
FORCE_SCRIPT_NAME = '/sentry'

But i don't know if it works

Here is the ingress resource for sentry :

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

回答1:


Your ingress does not work properly.

In nginx ingress docs you can read:

IMPORTANT NOTES: If the use-regex OR rewrite-target annotation is used on any Ingress for a given host, then the case insensitive regular expression location modifier will be enforced on ALL paths for a given host regardless of what Ingress they are defined on.

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

So if you want to use rewrite-target you should do it as following:

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


来源:https://stackoverflow.com/questions/61737995/how-to-expose-sentry-on-subpath-in-nginx-ingress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!