Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Not sure if this is the right stack exchange to post this. If there is a better place please redirect me - thanks.

I enabled these lines in httpd.conf:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Then I added these lines:

ProxyRequests Off

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

ProxyPass /goo http://google.ca
ProxyPassReverse /goo http://google.ca

If I open up my browser and go to this URL:

http://localhost/goo

I get redirected to:

http://www.google.ca

I expected that mod_proxy would act like a proxy and not just redirect to google. I would expect that my browser should NOT know that google.ca exists and should only know about the existance of the proxy server.

  1. What is going on here?
  2. Is this not what mod_proxy was designed for?
  3. Is there something else that I should be using instead?
share|improve this question
add comment

migrated from webmasters.stackexchange.com Jul 30 '13 at 21:51

This question came from our site for pro webmasters.

2 Answers

up vote 3 down vote accepted
  1. What is going on here?

Well, let's take a look at http://google.ca:

$ curl -D /dev/stdout http://google.ca
HTTP/1.1 301 Moved Permanently
Location: http://www.google.ca/
.
.
.
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.ca/">here</A>.
</BODY></HTML>

And there's your redirect. Google does this on google.com, google.ca, and probably others.

  1. Is this not what mod_proxy was designed for?

Sure. It's doing exactly what you asked it to do...it's fetching content from http://google.ca and returning it verbatim to your client.

  1. Is there something else that I should be using instead?

If you really want to act like a generic forward proxy on a particular URL, you're probably going to need to investigate mod_proxy_html, which can be used to rewrite links in content fetched from a remote server.

But in general, it's really hard to prevent a remote site from performing this sort of redirect (because even if you rewrite links in the Location header, in <A> tags, and elsewhere, you may miss some Javascript or something...)

share|improve this answer
    
Great Answer +1 –  bybe Jul 31 '13 at 6:43
    
So in conclusion: mod_proxy will continue to run links through the proxy only if they are relative URLs. –  sixtyfootersdude Jul 31 '13 at 13:42
1  
Technically: your browser will only continue to run links through the proxy as long as they point to your proxy. –  larsks Jul 31 '13 at 14:48
add comment

mod_proxy will in fact rewrite "Location," "Content-Location," and "URI" headers on HTTP redirect responses. As explained in larsks' answer the 301 google is doing causes

ProxyPassReverse /goo http://google.ca

to be ineffectual because the redirect to www.google.ca does not match.

You could try adding

ProxyPassReverse /goo http://www.google.ca

but it isn't clear what you are trying to accomplish.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.