Reverse proxy with URLs replacement

J
  • 17 Jun '23
Hello, 

Is it possible to use Nginx as a proxy for another website, while also having the ability to replace absolute paths in CSS, JS, and HTML content? 

For example, I would like to have an Nginx server running at the URL http://proxy1-server.com that proxies a web server running at the URL http://192.168.10.10 (private IP). The web server could be any server such as Apache, LiteSpeed, IIS, etc. I can achieve this using an Nginx reverse proxy, but I would also like to rewrite the absolute URLs within the CSS, JS, and HTML files from http://192.168.10.10/file.css to http://proxy1-server.com/file.css, in order to avoid any functionality issues when accessing the website from outside the network. 

The idea is to replace these URLs within the proxy server itself, rather than modifying the web server where the website is hosted. 

Thank you! 

Jose David Bravo Álvarez 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230617/51490854/attachment.htm>
R
  • 19 Jun '23
> Is it possible to use Nginx as a proxy for another website, while also having the ability to replace absolute paths in CSS, JS, and HTML content?

One way for that is to use proxy http://nginx.org/en/docs/http/ngx_http_proxy_module.html + sub module http://nginx.org/en/docs/http/ngx_http_sub_module.html 

The only caveat is that the sub module doesn't support compressed responses from backends so you need to switch it off by setting proxy_set_header Accept-Encoding "";

rr