A
A
Alexander Vasiliev2021-05-11 12:27:34
Nginx
Alexander Vasiliev, 2021-05-11 12:27:34

How to open another site without changing the current address when proxying in nginx?

I'm proxying from localhost to google. The task is as follows:

In the browser I enter proxy.localhost, I press enter
google.com opens, but proxy.localhost remains in the address bar in the browser (i.e. proxying is performed)
PROBLEM. It works for me as in the case of a redirect, not a proxy, i.e. after point 1, google opens and the entry in the address bar changes from proxy.localhost to https://www.google.com .

QUESTION. How can I make the address remain proxy.localhost but open https://www.google.com ?

Please help, I tried many options, rolled back to a more or less working one, here is my current code:

server {
  listen *:80;
  server_name proxy.localhost;
  location / {
     proxy_pass https://google.com/;
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Koryukov, 2021-05-11
@MadridianFox

In general, poxy_pass does exactly what you need.
See what exactly the server is responding to when you make a request. It may be that your nginx is proxying correctly, but the Google server sees that something is wrong with the request, and returns a redirect, of course, to its own domain, and not to yours. In this case, the browser will make another request and change the domain in the address bar.
If that's the case, try adding the google host header when you contact google:

proxy_pass https://google.com/;
proxy_set_header Host google.com;

A
AUser0, 2021-05-11
@AUser0

Basically
1) any JavaScript can check and rewrite the URL of the page it's running on;
2) any link on the page can redirect to the original site;
3) and there are also restrictions on CORS;
4) is HTML meta <base> by any chance not invented for browsers?
But your courage is commendable! Raise the banner, followers of Don Quixote!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question