I have written an nginx config map file for my kubernetes deployment.
apiVersion: v1
kind: ConfigMap
metadata:
name: api-svc
namespace: api
data:
nginx.conf: |
worker_processes 1;
events { worker_connections 1024; }
http {
server {
listen 80;
server_name my.abc.com;
location ~* ^/wservce/api {
proxy_pass http://my.abc.com:80;
}
}
}
Now when I hit my.abc.com/wservce/api it is working fine and sending the request to
http://my.abc.com:80/wservce/api
and I'm getting the response.
But when I hit my.abc.com/WseRvce/API it matches /wservce/api block because I have used ~*
but the request goes to
http://my.abc.com:80/WseRvce/API
for which we have not written any rules.
I want to send the request to http://my.abc.com:80/wservce/api only even if the request comes in uppercase or lowercase.
Solutions I have tried.
- I tried to hard code the proxy pass but it didn't work. Nginx pod went to crash loop backoff saying .
location ~* ^/wservce/api {
proxy_pass http://my.abc.com:80/wservce/api;
}
- Tried this map but again it is sending request to uppercase url.
http {
map $request_uri $lowercase_uri {
~^(?i)(.*)$ $1;
}
server {
listen 80;
server_name my.abc.com;
location ~* ^/wservce/api {
rewrite ^ $lowercase_uri break;
proxy_pass http://my.abc.com:80;
}
}
In my logs path is - Wservce/API only and gave 404.
- Tried this also but it is sending the request to uppercase only.
location ~* ^/wservce/api {
rewrite ~* ^/wservce/api/(.*)$ /wservce/api/$1 break;
proxy_pass http://my.abc.com:80;
}
In my logs path is - Wservce/API only and gave 404.
- I don't want to use any library for this like lua.
Note : Request is directly coming to nginx there is no ingress above it.
Summary : whenever I hit a url with Uppercase letters it goes to its corresponding block but in proxy_pass it takes the url with Uppercase while I want it in lowercase.