简体   繁体   English

kubernetes nginx 入口子路径到子域重定向

[英]kubernetes nginx ingress subpath to subdomain redirection

I am trying to achieve below proxy_pass settings, basically one of the services is listing to subdomain.example.com/guacamole but I want to serve it as subdomain.example.com我正在尝试实现以下 proxy_pass 设置,基本上其中一项服务是列出 subdomain.example.com/guacamole 但我想将其作为 subdomain.example.com 提供

    location / {
    proxy_pass http://guacamole:8080/guacamole/;
    proxy_buffering off;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    proxy_cookie_path /guacamole/ /;
    access_log off;
    # allow large uploads (default=1m)
    # 4096m = 4GByte
    client_max_body_size 4096m;
    }

Below is nginx ingress下面是nginx入口

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: guacamole-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  tls:
  - hosts:
    - subdomain.example.com
  rules:
  - host: subdomain.example.com
    http:
      paths:
      - path: /guacamole
        backend:
          serviceName: service-guacamole-frontend
          servicePort: 8080

I tried using nginx.ingress.kubernetes.io/rewrite-target: / but it didn't work.我尝试使用nginx.ingress.kubernetes.io/rewrite-target: /但它没有用。

Replacing path: /guacamole with path: / should do the trick.更换path: /guacamolepath: /应该做的伎俩。

  rules:
  - host: subdomain.example.com
    http:
      paths:
      - path: /  # replace `/guacamole` with `/`
        backend:
          serviceName: service-guacamole-frontend
          servicePort: 8080

You should use the app-root annotation.您应该使用app-root注释。

From nginx-ingress docs :来自 nginx-ingress 文档

If the Application Root is exposed in a different path and needs to be redirected, set the annotation nginx.ingress.kubernetes.io/app-root to redirect requests for /.如果Application Root暴露在不同的路径,需要重定向,设置注解nginx.ingress.kubernetes.io/app-root重定向/请求。

Try to use:尝试使用:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: guacamole-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/app-root: /guacamole
spec:
  tls:
  - hosts:
    - subdomain.example.com
  rules:
  - host: subdomain.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: service-guacamole-frontend
          servicePort: 8080

Here you can find another example. 在这里你可以找到另一个例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM