There is currently an app that is using cname host mapping with a third party app
the hostname for the third party app is mycompany.partner.com
and the current cname host map under my domain help.mycompany.com
so current routing is below
users => cloudflare DNS(help.mycompany.com) => cname host mapping(mycompany.partner.com) => partner app
now i want to do this
=> cname host mapping(mycompany.partner.com) => partner app
|
users => cloudflare DNS(help.mycompany.com) => my nginx => |
|
=> my frontend app
is this possible?
So basically i want all traffic to come to my own app via nginx now and then i route some traffic based on url path to the third party app and others to my frontend app
how can i achieve this with nginx? below are the url paths i want to route
this routes to my frontend app
help.mycompany.com/app/test1 => http://localhost:500/app/test1
help.mycompany.com/app/test2/test3 => http://localhost:500/app/test2/test3
help.mycompany.com/app/parameter?key=check => http://localhost:500/app/parameter?key=check
this rewrites/routes to partner app
help.mycompany.com/app/partner1 => https://mycompany.partner.com/app/partner1
help.mycompany.com/app/discuss/check => https://mycompany.partner.com/app/discuss/check
and all other paths
location block to route all url paths to the frontend app is below
location ^~ / {
rewrite ^/(.*)$ /$1 break;
proxy_pass http://localhost:500;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
but now i need to split some url paths to the partner app as stated above
so basically all traffic will pass through nginx as i will point DNS for help.mycompany.com to now point to my nginx reverse proxy and then routes and rewrites the url
Thanks
2
Answers
You have to create different location for uri paths. For Example:
In above case holds good for REST calls where are not trying to render static js or html files, which can be domain specific. You are rendering static js or html , trying adding those paths also to the domain there are present.
If you want to redirect specific location to particular domain, please take a look the example below:
In this case all the specified uri will get redirect to the domain one specify.
Remember to add the generic path, if nothing matches it will go to this one. Example below:
Below is the example for a sample conf.
Hit
http://localhost:8888/search?q=zenduty
on your browser to test. localhost nginx server will proxy the request on google search. One can add extra headers if needed, will proxying.