内置代理支持
¥Built-in Proxy Support
¥Stability: 1.1 - Active development
Node.js 创建全局代理时,如果 NODE_USE_ENV_PROXY
环境变量设置为 1
或启用 --use-env-proxy
,则全局代理将使用 proxyEnv: process.env
构建,从而基于环境变量启用代理支持。还可以通过在构建代理时传递 proxyEnv
选项来创建支持代理的自定义代理。如果只想从环境变量继承配置,则值可以是 process.env
,或者是一个具有特定设置覆盖环境的对象。
¥When Node.js creates the global agent, if the NODE_USE_ENV_PROXY
environment variable is
set to 1
or --use-env-proxy
is enabled, the global agent will be constructed
with proxyEnv: process.env
, enabling proxy support based on the environment variables.
Custom agents can also be created with proxy support by passing a
proxyEnv
option when constructing the agent. The value can be process.env
if they just want to inherit the configuration from the environment variables,
or an object with specific setting overriding the environment.
检查 proxyEnv
的以下属性以配置代理支持。
¥The following properties of the proxyEnv
are checked to configure proxy
support.
-
HTTP_PROXY
或http_proxy
:HTTP 请求的代理服务器 URL。如果两者都设置,则http_proxy
优先。¥
HTTP_PROXY
orhttp_proxy
: Proxy server URL for HTTP requests. If both are set,http_proxy
takes precedence. -
HTTPS_PROXY
或https_proxy
:HTTPS 请求的代理服务器 URL。如果两者都设置,则https_proxy
优先。¥
HTTPS_PROXY
orhttps_proxy
: Proxy server URL for HTTPS requests. If both are set,https_proxy
takes precedence. -
NO_PROXY
或no_proxy
:用于绕过代理的主机的逗号分隔列表。如果两者都设置,则no_proxy
优先。¥
NO_PROXY
orno_proxy
: Comma-separated list of hosts to bypass the proxy. If both are set,no_proxy
takes precedence.
如果请求是向 Unix 域套接字发送的,则代理设置将被忽略。
¥If the request is made to a Unix domain socket, the proxy settings will be ignored.