I have 2 react applications, one of which is served on example.com and it works fine.
Now I am working on a second application and I need it to be served on example.com/app.
I am using nginx as ingress.
Note:
Both apps run on seperate docker containers on AKS in same namespace.
Please find my ingress.yaml as below –
App1 served on example.com (works fine)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app1
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/ingress.allow-http: "true"
labels:
app: app1
spec:
ingressClassName: nginx
rules:
- host: example.com
http:
paths:
- backend:
service:
name: app1
port:
number: 80
path: /
pathType: Prefix
App2 which I need to serve on example.com/app (doesn’t work). When I open example.com/app/ I see a blank page and no errors. When I open example.com/app the bundles fail to load.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app2
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
labels:
app: app2
spec:
ingressClassName: nginx
rules:
- host: example.com
http:
paths:
- backend:
service:
name: app2
port:
number: 80
path: /app(/|$)(.*)
pathType: Prefix
2
Answers
I had to add
"homepage": "https://example.com/app"
in my package.json to make it work.If it’s just about the serving example.com/app not sure how your internal application showing or serving the data.
Can’t you just do like
You can also separate out the two different ingress hosts with diff name
while the other one is without the rule of rewrite forwarding all traffic to svc-1.