'how to forward request_uri from ingress to backend pods via service
I am sharing my ingress file and also working nginx conf file
not working ingress for path based routing
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: originqa-ingress
namespace: logging
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
ingressClassName: nginx
rules:
- host: originqa-test.example.com
http:
paths:
- backend:
service:
name: svc-originqa
port:
number: 5000
path: /
pathType: Prefix
- backend:
service:
name: svc-originqa-sitemap
port:
number: 80
path: /(.+\.(?:xml))$
pathType: Prefix
and given below nginx.conf is producing correct result which I have translated to above ingress. but if any request coming to / then it is working. but I have created a regex "/(.+.(?:xml))$" which basically is, if anything ends with .xml just after / like "/sitemap_index.xml" then it is not working. it is happening because ingress is not forwarding $requst_uri to backend pods via svc-originqa-sitemap service.
So can anyone please help me with this?
Problem:- nginx-ingress is not forwarding $request_uri to backend pods via svc-originqa-sitemap service.
desired solution:- svc-originqa-sitemap:80$request_uri
################# working nginx conf ###############################
server {
listen 80;
server_name sitemaptest.example.com;
error_log /var/log/nginx/sitemap.error.log;
access_log /var/log/nginx/sitemap.access.log;
location ~ /(.+\.(?:xml))$ {
proxy_pass http://10.0.1.44:202$request_uri;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
