Ingress controller: nginx-ingress-controller version: 0.9.0-beta5
I'm trying the Kubernetes Ingress feature for the loadbalancing task in a project of moving to kubernetes deployments. The nginx ingress controller seems to be more stable and mature, so I'm using it for the task.
With my setup, I have to use the rewrite-target annotation, because I have 2 types of containers to proxy, so I use a different path for each of them, but I don't want that path to be forwarded to the apps running in the containers, so I just use rewrite-target: / and the apps running in the containers receive the requests as if they were for the root path /.
The problem is that when I try to access to any of the apps with my browser, it connects with the app, but then the response may include some redirection (for example adding a trailing /) and that redirection is to the root path /, without including the app's path as indicated in the ingress rule. Even if I use a path so I wouldn't get any redirect response from the app, the browser downloads the HTML correctly, but all the elements like css or images are pointing to the root path / also, so the browser is not able to download them. (the apps that I'm running in the containers are Oracle WebLogic Server instances, some are admin servers and other ones are managed servers with some JEE apps deployed).
Is there any way to achieve the path rewriting in both directions, so the requests to the app's relative path would be rewritten to the root path, but all the returning requests to the root path would be rewritten in the opposite way, from root path to the relative path, so the client's browser could successfully get the following requests.
I'm using the following ingress rules descriptor:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/ingress.class: "nginx"
ingress.kubernetes.io/affinity: "cookie"
ingress.kubernetes.io/session-cookie-name: "route"
ingress.kubernetes.io/session-cookie-hash: "sha1"
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /adminapp
backend:
serviceName: container-admin
servicePort: *****
- path: /managedapp
backend:
serviceName: container-managed
servicePort: *****
So with this setup, I basically make a request to NGINX_IP/adminapp/console/, and it tries to redirect me to NGINX_IP/console/login/LoginForm.jsp, but this request fails because it doesn't include the adminapp prefix in the path. It would work if the request was NGINX_IP/adminapp/console/login/LoginForm.jsp instead. In fact, if I manually change the request path to NGINX_IP/adminapp/console/login/LoginForm.jsp, it downloads the HTML of that page, but all the resources of that page point to paths in the NGINX_IP/console/*.png format, so all of them fail.
Is it possible to fix this situation and get all of the requests correctly rewritten, in both ways of the connections (to and from the upstream servers) ?
I would really appreciate any help!
+1 for this. I have the same question
+1
+1
Is it possible to fix this situation and get all of the requests correctly rewritten, in both ways of the connections (to and from the upstream servers) ?
You can achieve this using the sub_filter module, something like
sub_filter "http://your_server/" "http://your_server/admin/";
sub_filter_once off;
but doing this your CPU usage will increase and you could see an increase in the response time.
I suggest you change your application to return relative assets.
ingress.kubernetes.io/add-base-url: "true" as annotation on my Ingress works for me.
Most helpful comment
ingress.kubernetes.io/add-base-url: "true"as annotation on my Ingress works for me.