I want to route the traffic from a domain to another domain(with different subpath) without change the URL in brower using Nginx.
For example, I /app/example/ —> https://another_domain.com:443/dev/app/
I have tried using
location /app/example/ {
proxy_pass https://another_domain.com:443/dev/app/;
proxy_ssl_server_name on;
}
But the URL in the browser will be changed to "https://another_domain.com:443/dev/app/" when I try to access "/app/example", that it not what I want.
I have also tried using the same subpath:
location /app/example/ {
proxy_pass https://another_domain.com:443;
proxy_ssl_server_name on;
}
The URL in the browser does not change, but my requirement is to route traffic to another subpath in another domain.
Could anybody help me? How can I route the traffic to another subpath of another domain using Nginx without changing the URL in browser?
2
Answers
You can’t.
Proxying isn’t a good solution, as you’ll likely break some resources on the page by serving them from a different domain.
The best you can do is create a page that has nothing but an iframe, which loads the other site. And, this only works if the target site doesn’t have frame busting.
To get this working correctly, you’ll need to own and control the responses of the destination server to ensure the HTML sub-resources (images, CSS, JS) work correctly. As Brad said, it’s difficult to proxy third-party sites you don’t control. Typically, the relative
href
andsrc
tags in the destination HTML response need to use absolute URLs of the destination server URL.When done correctly using absolute URLs, this works:
From these third-party examples, you can see how Google search is missing sub-resources. Bing detects the proxy outright and redirects to its own domain.