[yet another] proxy question - rewrite URLs

Francis Daly francis at daoine.org
Thu Apr 30 17:37:53 UTC 2015

On Mon, Apr 27, 2015 at 11:05:53AM -0400, DigitalHermit wrote:

Hi there,

> I can successfully redirect the following using 301 returns:

> location /webhost1/ {  
>   return 301 [https]//$host$request_uri;
> }

I'm not sure that does what you indicated that you want it to do; but
you also say that it works fine, so I'll believe that part.

> I then do another redirect inside the 8443 listener:

Note: there is no redirect here.

And your webhost1 and webhost2 seem to have become confused, unless I'm
missing something.

> The above works so far. The problem occurs because there are some links that
> refer to webhost2 directly. I can fix some of these with proxy_set_header
> statements. However, webhost1 has multiple links to a page on webhost2. 

What do you mean when you say "links"?

HTTP response headers, or HTTP response body content?

nginx can relatively easily modify response headers. nginx can less easily
modify response body content.

> Is there a way to reverse proxy to webhost1 and somehow intercept all
> webhost2 requests and in turn proxy them through another port on ico-proxy?

Can you describe what you want, in terms of one request / one response
at a time?

I think it is:

client requests https://ico-proxy/webhost1/file
nginx responds with the content from https://webhost1/webhost1/file

That content includes in its body a html link to https://webhost2/file. So:

client requests https://webhost2/file, but fails to get any response
because it can't access webhost2.

What part of that have I got wrong?

(Please be specific. Ports and urls and webhost1 and webhost2 do matter here.)

You probably will need to get nginx to reverse-proxy content on
webhost2. It's not immediately clear to me whether you are better off
making the client believe that ico-proxy *is* webhost2; or trying to
edit the html link in the content returned from webhost1.

Good luck with it,

Francis Daly        francis at daoine.org

More information about the nginx mailing list