Accessing web services via AJAX by creating an Apache pass-through proxy on Windows

I've been working with a certain client for several years, and in that time I've built quite a few web sites for this client. Each of these sites connects to a web service that I developed and maintain. This web service delivers real-time numerical data, which the individual client sites use to populate charts and tables.

Each site was built in ASP.Net, which allowed me to perform server-side processing to connect to the web service, fetch the data, and use it to populate controls on the page. That was all fine and dandy, especially since .Net provides lots of simple tools for web service handling. All fine until this week, when I received a request for a new site, one that has the requirement of no server-side processing.

This means a web site built entirely in html and javascript.

Luckily the client provided some javascript libraries for facilitating synchronous and asynchronous calls, meaning I didn't have to write code from scratch, nor did I have to create a custom jQuery solution. That doesn't mean that the development was without problem, though.

I quickly ran into a very big browser issue: Most browsers don't allow cross-domain AJAX requests (IE has ways to getting around this). This means that they restrict AJAX requests to the same domain as the original page, and therefore I got a browser error when loading a page on localhost, and trying to make an AJAX connection to the live web service.

The solution is pretty easy, and involves creating a pass-through Proxy. The trick is to make a call to a local URI, and have Apache pass that request along to the web service. That way Firefox is happy because it thinks that all AJAX requests are made to the same domain, but in fact Apache is acting as your proxy and calling the web service for you.

There's a lot of documentation out there on how to do this, but I want to provide a concise, easy-to-understand set of instructions for Windows users.

Here's the two quick and easy steps to create an Apache pass-through proxy:

1) Make sure 'proxy' and 'proxy_http' modules are enabled. On Unix you should use the simple "configure" command to do this, but on Windows this means uncommenting the following lines in httpd.conf:

LoadModule proxy_module modules/
LoadModule proxy_http_module modules/

2) In httpd.conf, create the proxy rule. For the a rates service with the url, this means adding something like this line:

ProxyPass /service

Then make sure you restart Apache.

Now you can make AJAX calls to /service, and Apache will pass it through to, and you'll be on your way!



Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.