Apache behind corporate proxy

2019-04-18 17:25发布

问题:

I'm developing a php application. I'm using wamp and I'm behind a corporate proxy. I'm using cntlm to authenticate NTLM. I need to curl google geocoding api, in order to do this I used the following settings that are working:

    curl_setopt($ch,CURLOPT_PROXY, '127.0.0.1:3128');
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);

I'd like to find a way to avoid setting those options for CURL. I believe I can play with Apache setting, but I'm not sure. The reasons I need to find this solution are:

  1. In production env there will be no such a proxy (at the moment the above options are used only if the environment variable is set to DEV env, but still: it's not the best solution)
  2. If I want to use 3rd party SDK (such as facebook php sdk), those are internally using CURL but they do not necessarily expose method to change CURL options (for example facebook sdk doesn't). I don't want to change the SDK source code to fit my proxy

What I tried:

So far I turned on proxy_module on apache and I added the following line on httpd.conf, but with no success

ProxyRemote * http://127.0.0.1:3128

I still can't access the internet. I googled a lot, but I couldn't find a solution, any ideas?

I could find many people talking about the same issue, but I didn't find any comprehensive solution, for this reason I raise a bounty.

What I found:

There is this bug in which I found: But I'm not sure if this will work for curl and anyway I can't find how to modify the php.ini

[2010-12-20 14:03 UTC] jani@php.net -Summary: changing the default http-wrapper +Summary: Add php.ini option to set default proxy for wrappers -Package: Feature/Change Request +Package: Streams related -PHP Version: 5CVS +PHP Version: *

and

[2011-04-05 11:29 UTC] play4fun_82 at yahoo dot com Hi, i have the same problem. My solution was to pass through proxy server with cntml tunneling tool. You configure cntml proxy to forward http request received on local host on a port to destination with proper authentication.

And in pear u just configure

pear config-set http_proxy 127.0.0.1:3128

3128 - is port configuret in cntlm(it can be any other free port).

Thanks very much

回答1:

You're saying you want this functionality on WAMP, for your development computer only, right? The SDK's work without modification in production, so you can just take advantage of your Window's Host file to redirect requests.

Here's a walkthrough.



回答2:

I think you can do it through proxy tools like Proxifier(http://www.proxifier.com).

AFAIK, they can capture traffic from selected applications and redirect to a proxy automatically.

Not a perfect solution but should be useful on dev machine.



回答3:

After reading this article I was about to throw in the towel, but there is actually an easy solutiuon. I had to play with windows environment variable, at the end setting a system variable to https_proxy=https://localhost:3128 worked! Before it was not working because I was setting it to 127.0.0.1:3128. Run the command

reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | find /i "proxyserver"

then copy/paste the answer in the system variable and now it's working!!