Advanced Rewrite request url to match the query string and normalization

Francis Daly francis at daoine.org
Sun Mar 3 10:39:30 UTC 2019


On Tue, Feb 26, 2019 at 11:07:34PM -0500, shadowgun1102 wrote:

Hi there,

> I have a simple nginx forward proxy, configured as:

nginx is not a forward proxy, and therefore there will be "rough edges"
when you try to use it as such. That's fine, so long as you know.

> The client behind its isp firewall sends the request (per nginx log): GET
> http://www.clientisp.com/path/rewrite.do?url=http%3A%2F%2Fwww.example.com
> HTTP/1.1
> 
> How do I transform the requested url to http://www.example.com before it is
> sent to the upstream?

I think that you cannot do this with just stock-nginx.

You will probably need one of the embedded-language modules, or some
other third-party modules, such as are in the "openresty" distribution.

> I looked up many posts online, but I am still confused at:
> 
> 1. The online examples usually teach how you match the uri part, but my
> goal is to obtain the queried string only, i.e., everything after the
> equation mark"=", http%3A%2F%2Fwww.example.com.

You would use "location = /path/rewrite.do", because that it what
"location" matches on.

Then you would probably make use of the variable $arg_url.

> 2. I have no idea how to decode the percentage coded symbols into
> normalized one.

That's where you would need something non-stock, perhaps
set-misc-nginx-module

Note that you will also possibly want to mangle the response from
upstream, so that any string that the browser might interpret as a url,
will expand to the url that you want it to be.

By that, I mean that if the response from http://www.example.com includes
an "img src" of "/image.png" that gets back to the browser, what request
will the browser make for that image? And will that request work, in
your setup?

Good luck with it. It looks difficult to me.

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list