Transparent rewrite with nginx ingress

Hello everyone.

I would like to do the following with the existing nginx ingress controller of Rancher 2 / Kubernetes:

server {
    listen 80;
    server_name $hostname localhost;

    auth_basic "Restricted";
    auth_basic_user_file pathtofile;

    location /kibana {
        rewrite ^/kibana/(.*)$ /$1 break;
        proxy_pass http://localhost:5601/;
    location ~ ^/es(.*) {
        rewrite /es/(.*) /$1  break;
        proxy_pass http://localhost:9200;

Is it even possible to accomplish this in an easy way using annotations and ingress controller configuration? If not? How do you suggest to takle this problem?

Thank you!

Hi qdrop17,

I’m not an expert at all but here how I would do it using the rancher gui.

You should look at the following annotation of the nginx ingress: /

using that annotation would enable you to trim out your selecting path (eg: /es/) before sending request to your selected service.

So create your load balancing rule in rancher gui (hostname, path, selector/workload) add the “ /” to the annotation… and you should be go to go


1 Like