在 Debian 上配置 Node.js 的代理,通常取决于你指的是哪一种“代理”。下面按常见场景说明。
如果你是想让 npm install 走代理(公司内网、科学上网等):
npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890
npm config set proxy http://user:pass@127.0.0.1:7890
npm config set https-proxy http://user:pass@127.0.0.1:7890
npm config get proxy
npm config get https-proxy
npm config delete proxy
npm config delete https-proxy
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
node app.js
永久生效(用户级):
echo 'export HTTP_PROXY=http://127.0.0.1:7890' >> ~/.bashrc
echo 'export HTTPS_PROXY=http://127.0.0.1:7890' >> ~/.bashrc
source ~/.bashrc
const axios = require('axios');
const httpsProxyAgent = require('https-proxy-agent');
const agent = new httpsProxyAgent('http://127.0.0.1:7890');
axios.get('https://example.com', { httpsAgent: agent });
sudo nano /etc/environment
添加:
HTTP_PROXY=http://127.0.0.1:7890
HTTPS_PROXY=http://127.0.0.1:7890
sudo nano /etc/apt/apt.conf.d/95proxy
Acquire::http::Proxy "http://127.0.0.1:7890";
Acquire::https::Proxy "http://127.0.0.1:7890";
yarn config set proxy http://127.0.0.1:7890
yarn config set https-proxy http://127.0.0.1:7890
docker run -e 中设置如果你能说明:
我可以给你更精确的配置示例。