I'm having trouble deploying a webshell on Kubernetes using nginx ingress. I'm rewriting all request going from /apple to / on my backend. The backend is hosting b374k webshell on /. I'm able to access the webshell form /apple but when I click on something the request is send to / instead of /apple/... which results in 404. Is it possbile to solve this without changing the webshell's code?
Kubernetes Manifest:
#Definition eines Srvices für ein Deployment
apiVersion: v1
kind: Service
metadata:
name: hip-service
namespace: hip-test
spec:
selector:
app: hip
ports:
- port: 80
---
#Definition Reverse-Proxy für einen Service
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hip-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: "false"
ingress.kubernetes.io/ssl-redirect: "false"
namespace: hip-test
spec:
rules:
- http:
paths:
- path: /apple
backend:
serviceName: hip-service
servicePort: 80
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 /
.
Taken from the nginx ingress docs :
IMPORTANT NOTES : If the
use-regex
ORrewrite-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.
So if you want to use rewrite-target you should do it as following:
Definition Reverse-Proxy für einen Service
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hip-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/ssl-redirect: "false"
ingress.kubernetes.io/ssl-redirect: "false"
namespace: hip-test
spec:
rules:
- http:
paths:
- path: /apple/(.*)
backend:
serviceName: hip-service
servicePort: 80
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.