• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

Proxying http requests?

Hi,

I'm working on a javascript project. My script has to access a php file on my remote server.

So the javascript file is running locally on my machine, the php script it wants to access is on the remote server, and I guess I run into the same origin policy problem because of that.

Is it possible to somehow have my script access a version of apache running locally, which then just proxies the request to my real remote web server? Ideally it would just take the requested URL, send it to my remote server, then respond with whatever data my remote server would have sent back anyway.

Thanks
0
DJ_AM_Juicebox
Asked:
DJ_AM_Juicebox
1 Solution
 
giltjrCommented:
You can setup Apache to be  a proxy server:

     http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
0
 
DJ_AM_JuiceboxAuthor Commented:
Ok that seems to be what I need. I'm on a max os 10.5 machine, so it's already running apache, I was able to verify that. I have the http.conf file here, am I supposed to add the proxy statements there?

The example given in the page you linked:

  ProxyRequests On
  ProxyVia On

  <Proxy *>
    Order deny,allow
    Deny from all
    Allow from internal.example.com
  </Proxy>

is that literally would be added to http.conf (although internal.example.com I would replace with www.mysite.com) ?

Thanks
0
 
samriCommented:
hi,

to my understanding, the JS file would be executed on client browser, while the PHP would be executed on the Apache/server.

to understand the scenario:

>> I'm working on a javascript project. My script has to access a php file on my remote server.

Hence, the original url : http://site1.domain.com/something.js, would have some embedded hyperlink, in the format http://remote.domain.com/something.php

In order for the something.php to be executed, this url needs to be "loaded" by the client broser.  in other words, the client need to have access to the http://remote.domain.com/

the mod_proxy (as commened by giltr) would be useful to enable the apache  on site1 to proxy the request to the apeche on server remote.

how this could be achieved would depends on how the JS is coded.  what I could think of is, you have all the php on the remote server (lets use remote.domain.com), and in the site1.domain.com, have a reverse proxy setup to proxy the request for the php scripts.

in site1.domain.com;

ProxyPass /scripts  http://remote.domain.com/pathtoscripts
ProxyPassReverse /scripts http://remote.domain.com/pathtoscripts

and in you JS file; have the PHP loaded as http://site1.domain.com/scripts/something.php

I hope i am interpreting your intention correctly, and be of some help -- as oppose to confuse things..

happy new year!



0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now