0

I want to proxy requests with nginx to different domain and also rewrite some part of the path. For example

http://origin.com/ - > http://target.com/_plugin/kibana

How to accomplish such automated addition of _plugin/kibana part to any route that I request and forward to my target server

server {
    listen 80;
    server_name _;
    location / {
        proxy_set_header X-Forwared-Proto $scheme;
        rewrite ^(.*)$ /_plugin/kibana/$1 break;
        proxy_pass https://my-es-custer-in4lf3ruqx6shv2ndhju.us-east-1.es.amazonaws.com/;

    }
}

Should I have different location blocks or should I have a rewrite directive on a server level for this to work properly?

1 Answer 1

1

You do not need to use rewrite for your case, since you want to append _plugin/kibana to any routes.

Assuming the nginx config is for http://origin.com/:

server {
    listen 80;
    server_name origin.com;
    location / {
        proxy_set_header X-Forwared-Proto $scheme;

        # http://origin.com/req/1/2 will go to http://target.com/_plugin/kibana/req/1/2
        proxy_pass http://target.com/_plugin/kibana;

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.