Nginx rewrite redirects using proxy_pass

Viewed 784

Is it possible to access an address and upload its content without having to redirect to the original site?

What I'm trying to do, I want my users inside my internal network that access the internal site mysite.digital be presented with the content of the external site ( hosted on Cloudflare) https://siteseguro.com

I can also remove from Cloudflare if necessary

I got it with the configuration below, but when accessing the site it redirects me to the original URL. I need to hide the DNS/IP of the real website.

server {
    listen 80;

    location ^~ / {
        proxy_pass https://brasilia.com;
        proxy_set_header Host brasilia.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Referer $http_referer;
    }
}
1 Answers

You have two separate problems

Redirect

Redirects are caused by two headers Location and Refresh. Nginx offers you proxy_redirect that will handle that for you:

proxy_redirect https://brasilia.com http://mysite.digital;

Links

The website may contain relative links /link or link, in which case you are ok with the first solution. In case there are complete links to the original URL (https://brasilia.com/link or //brasilia.com/link) you will need to rewrite also the response body. Rewriting the body is something described here.

Related