2

I have a bunch of subdomains in one single server:

  • a.example.com
  • b.example.com
  • news.example.com

All of them are in the same Apache virtualhost.

I need to use a feed provided by the news subdomain inside the a and b subdomain. The feeds typically look like this:

  • news.example.com/news/a
  • news.example.com/news/b

On the a and b subdomains, I'm using jquery's ajax function to load the data from the news feeds, and present it on a and b. This initially didn't work, because of the same-origin policy.

I was able to override this by adding the Access-Control-Allow-Origin "*" to my Apache config file.

... but this works only in Firefox, Chrome and Safari. Internet explorer seems to ignore that directive.

Thus, I need to create a proxy.

What I need is a new directory in all my subcomains (for example /proxy) that Apache detects, and redirects to news.example.com, no matter what the subdomain. So:

  • a.example.com/proxy/news/a -> return the contents of news.example.com/news/a
  • b.example.com/proxy/news/b -> return the contents of news.example.com/news/b

Can I do this directly in Apache + submodules (for example, mod_rewrite), or do I need to use a scripting language like PHP for doing this?

kikito
  • 51,734
  • 32
  • 149
  • 189

3 Answers3

2

You want the ProxyPass Directive.

ProxyPass /proxy/news/a http://news.example.com/news/a
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks, your answer put me on the right track! At the end, I had to combine mod_proxy with mod_rewrite though - I couldn't make ProxyPass work as you wrote there. – kikito Feb 24 '12 at 10:35
1

At the end we were able to make the proxy using a combination of two modules: mod_rewrite and mod_proxy.

The syntax was the following:

rewriteEngine on
rewriteRule proxy/(.+)$ http://news.example.com/$1 [P]

The [P] at the end is telling the rule "act as a proxy" and doesn't work without mod_proxy. Without it, apache makes a "redirect" (the url at the top of the page changes) instead of "just serving the page".

kikito
  • 51,734
  • 32
  • 149
  • 189
0

Apache can be configured to use apache:

consider this working sample code (proxy part):

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName ci.testserver.com
    ServerAlias ci
    ProxyRequests Off
    <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>
        ProxyPreserveHost on
        ProxyPass / http://localhost:8080/
</VirtualHost>
linuxeasy
  • 6,269
  • 7
  • 33
  • 40