Node.js global proxy setting

前端 未结 5 2264
孤城傲影
孤城傲影 2020-12-12 16:58

I was working in a corporate network behind a proxy server. In my code I can set the proxy by using the approach mentioned in this thread.

But the problem is that mo

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 17:34

    While not a Nodejs setting, I suggest you use proxychains which I find rather convenient. It is probably available in your package manager.

    After setting the proxy in the config file (/etc/proxychains.conf for me), you can run proxychains npm start or proxychains4 npm start (i.e. proxychains [command_to_proxy_transparently]) and all your requests will be proxied automatically.

    Config settings for me:

    These are the minimal settings you will have to append

    ## Exclude all localhost connections (dbs and stuff)
    localnet 0.0.0.0/0.0.0.0
    ## Set the proxy type, ip and port here
    http    10.4.20.103 8080
    

    (You can get the ip of the proxy by using nslookup [proxyurl])

提交回复
热议问题