URL Redirect Problems

Hello everyone,

I’m having problems attempting to redirect to another website. My
objective here is when I visit “Site A” and click on a link, it will
take me to another site on the same server, “Site B”. The URL has to
look like that you’re still on “Site A” while displaying content from
“Site B”. This is what my vhost.conf looks like right now.

server {
  listen *:80;
  charset utf-8;
  #server_name vbox.proxy.mysite.com;

  access_log /var/log/nginx/mysite.proxy.access.log;
  error_log /var/log/nginx/mysite.proxy.error.log error;

  root /home/webuser/webroots/mysite/utilities;

  location /tango {
      rewrite ^ http://vbox.bravo.mysites.com permanent;
  }
}

I’d go to “vbox.proxy.mysite.com/tango” and I’ll be redirected to
http://vbox.bravo.mysites.com”, which is great in the sense that the
content is displayed and I’m able to navigate the site normally. Any
advice?

Posted at Nginx Forum:

Try this:

location /tango {
    rewrite ^(.*)$ http://nginx.org/ permanent;
}

Posted at Nginx Forum:

It does the same thing as what I have. I’ve tried using proxy_pass, but
all it does is load up text and none of the images work.

Posted at Nginx Forum:

Thank you for the advice, Francis. I do own both websites and they exist
on the same server. I’ll try to clarify in what I’m trying to achieve. I
want the URL to stay the same in the browser (which would be
http://proxy.mysite.com/tango”) but display all of the content display
from “http://bravo.mysite.com” and also be able to view other content on
that page. There are frankly, way too many links for me to change in
order to do this, so I thought I’d do it with nginx. So when a user
visits “http://proxy.mysite.com/tango”, they stay on that URL, but
they’re actually on “http://bravo.mysite.com/” and could surf that site
normally.

Posted at Nginx Forum:

On Fri, Nov 12, 2010 at 10:30:05AM -0500, fwKilo wrote:

Hi there,

It does the same thing as what I have. I’ve tried using proxy_pass, but
all it does is load up text and none of the images work.

As a reminder, that was:

    location /tango {
      rewrite ^ http://vbox.bravo.mysites.com permanent;
    }

If you want not to change the url in the browser bar, you must not issue
a redirect (= an external rewrite).

Since the content is on a different server, you cannot just use an
internal rewrite – you must use proxy_pass.

If you control the http://vbox.bravo.mysites.com server, you will
find it much easier if you can configure it to serve from the “/tango”
url space (as in, http://vbox.bravo.mysites.com/ is empty apart from
http://vbox.bravo.mysites.com/tango/, which then has all the content
below there) – otherwise, you will have to ensure that all links within
the content are changed to include “/tango” as necessary, yourself.

(That’s presumably why the “none of the images work” – the browser
requests /tango/file.html, which refers to /image.png; the browser then
requests /image.png, which your proxying server does not proxy because
it does not start with /tango.)

See the Fine Manual (on the wiki) for some other configuration
directives
that should help with the header rewriting, if necessary.

All the best,

f

Francis D. [email protected]

On Fri, Nov 12, 2010 at 01:06:51PM -0500, fwKilo wrote:

Hi there,

Thank you for the advice, Francis. I do own both websites and they exist
on the same server. I’ll try to clarify in what I’m trying to achieve. I
want the URL to stay the same in the browser (which would be
http://proxy.mysite.com/tango”) but display all of the content display
from “http://bravo.mysite.com” and also be able to view other content on
that page.

Right.

So the browser asks for http://proxy.mysite.com/tango/one.html,
and it gets the content from http://bravo.mysite.com/one.html,
which will link to and include other urls – which will be of
the form “http://bravo.mysite.com/one.png” (in which case the
browser will go directly to bravo, bypassing proxy); or of the form
“/one.png” (in which case the browser will complete that url to
http://proxy.mysite.com/one.png”, which will probably fail to be served
correctly); or of the form “one.png” or “./one.png” or something else
that does not start with “/” (in which case the browser will complete
the url to “http://proxy.mysite.com/tango/one.png”, and the request
should succeed).

So you must ensure that every link that comes back from
every page within “http://bravo.mysite.com” does not start with
http://bravo.mysite.com” and does not start with “/”. Or, they must be
adjusted before they go to the browser.

There are frankly, way too many links for me to change in
order to do this, so I thought I’d do it with nginx. So when a user
visits “http://proxy.mysite.com/tango”, they stay on that URL, but
they’re actually on “http://bravo.mysite.com/” and could surf that site
normally.

Yes, they can. But only if anything that the browser might
interpret as a url to be completed, is correct according to the
http://proxy.mysite.com/tango” url space by the time it reaches the
browser.

This isn’t an nginx thing, it’s a (html) url-resolving thing.

You can filter the content in nginx on every request (although it’s
unlikely to be easy to do right), or you can set it right once on the
back-end.

(I assume it isn’t already all right on the back-end, because you report
none of the images working. The html returned, and the web servers’
logs should show you exactly why they aren’t working.)

Since the two sites are on the same server, you might be able to
configure
“proxy” to serve the “bravo” files directly. But that won’t help the
“partial urls starting with /” thing.

Whichever you choose, good luck with it,

f

Francis D. [email protected]