58511

Apache - Can I make a proxy server with just Apache?

I have a bunch of subdomains in one single server:

    <li>a.example.com</li> <li>b.example.com</li> <li>news.example.com</li> </ul>

    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:

      <li>news.example.com/news/a</li> <li>news.example.com/news/b</li> </ul>

      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:

        <li>a.example.com/proxy/news/a -> return the contents of news.example.com/news/a</li> <li>b.example.com/proxy/news/b -> return the contents of news.example.com/news/b</li> </ul>

        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?

        Answer1:

        You want the ProxyPass Directive.

        ProxyPass /proxy/news/a http://news.example.com/news/a

        Answer2:

        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".

        Answer3:

        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>

Recommend

  • F# OleDb Syntax Error in INSERT INTO Statement Pulling Data from Access to Linked SQL Server
  • Add vertical separator and labels to R barplot
  • Access Control Allow Origin header not present with fetch api call
  • Extracting Remote endpoint Object from Spring websocket session
  • git push origin master denied to user X where x is NOT the user in the local git config
  • How to make a local git repository that mirrors an upstream repository?
  • CFNetwork SSLHandshake failed (-9806) & (-9800) & (-9830)
  • Accessing Windows Azure Queues from client side javascript/jquery
  • Linux over commit heuristic
  • JSON - slashes not escaping
  • Problems with toDataURL HTML5 other ways to get canvas data?
  • Google Maps api v3 get start and end coordinates of a street
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Update CALayer sublayers immediately
  • Display issues when we change from one jquery mobile page to another in firefox
  • JFileChooser in front of fullscreen Swing application
  • Nant, Vault & Windows Integrated Authentication
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • Bug in WPF DataGrid
  • How to recover from a Spring Social ExpiredAuthorizationException
  • ILMerge & Keep Assembly Name
  • Large data - storage and query
  • jQuery tmpl and DataLink beta
  • How can I estimate amount of memory left with calling System.gc()?
  • Apache 2.4 - remove | delete | uninstall
  • WOWZA + RTMP + HTML5 Playback?
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Circular dependency while pushing http interceptor
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Benchmarking RAM performance - UWP and C#
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • unknown Exception android
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • git trying to push non-existent file … after clearing cache