There're still a few tools (eg.
npm, the Node Package Manager) that only support HTTP proxies and not SOCKS proxies. There're a couple of tools to "socksify" programs without builtin SOCKS support, but they do not work in all scenarios (eg. statically compiled apps, etc.). As a matter of fact, I tried to use
npm
like this, but it failed with an error message.
So what do you need to work around the issue? An HTTP proxy that can forward the incoming requests over a SOCKS proxy. Polipo can do that for you.
It's not developed/supported anymore, but still many linux distributions do have a polipo package even in their latest versions. Eg. Ubuntu 16 and 18 do have one, but Ubuntu 20 does not, so recently you'll have to find a PPA or compile it yourself. Debian does have a polipo package in it's last 3 releases (Jessie, Stretch, Buster), including the currently latest release.
To install polipo, a simple
apt-get install
will do.
To configure it, edit (in case of Ubuntu)
/etc/polipo/config
and add the following few lines:
socksParentProxy = "127.0.0.1:9999"
socksProxyType = socks5
proxyAddress = "127.0.0.1"
proxyPort = 8888
This will make polipo listen on TCP port 8888 on the 127.0.0.1 address for incoming HTTP proxy requests and forward them to a SOCKS proxy on TCP port 9999 on 127.0.0.1.
You can test how it works with curl:
# first we test directly the SOCKS proxy (just to make sure it works as expected)
curl -I -v -x socks5://127.0.0.1:9999 https://www.google.com/
# then we test polipo
curl -I -v -x http://127.0.0.1:8888 https://www.google.com/
In my case I used it with npm.
To set the proxy in your user config, try this:
npm config set proxy http://127.0.0.1:8888
Setting (and exporting) the http_proxy environment variable didn't seem to always work with npm.
P.S.: in case you're in a highly restricted environment (desktop/OS), you might need to add an iptables rule as well to grant access for your user (or any user) to polipo's HTTP proxy port and/or grant access for polipo's user to access the SOCKS proxy.
P.S.#2: there's already a nice writeup on this subject at
https://medium.com/@jamesjefferyuk/how-to-use-npm-behind-a-socks-proxy-c81d6f51dff8, but in the polipo config example it uses different characters for the opening and closing quotation marks and copy&pasting this into a polipo config will break it quite mysteriously. Polipo won't put anything about this in it's logfile ... as a matter of fact I couldn't make polipo write anything useful in it's log, even by raising the logLevel to it's maximum value. If you run polipo from the commandline, it'll complain about invalid lines in the config file though with exact linenumbers, so luckily I didn't have to look into the source.
Recent comments
2 years 25 weeks ago
3 years 46 weeks ago
3 years 47 weeks ago
3 years 48 weeks ago
3 years 49 weeks ago
4 years 4 weeks ago
4 years 4 weeks ago
4 years 4 weeks ago
4 years 4 weeks ago
4 years 5 weeks ago