只配http-proxy会卡在“Loading composer repositories”,因为Packagist等所有请求均走HTTPS,而http-proxy仅影响HTTP请求;HTTPS请求必须由https-proxy触发CONNECT隧道,缺一不可。

为什么只配 http-proxy 会卡在 “Loading composer repositories”
因为 Packagist、GitHub 等所有元数据和包下载请求全走 HTTPS,而 http-proxy 字段仅影响 HTTP 请求;HTTPS 请求必须由 https-proxy 字段触发 CONNECT 隧道,缺一不可。漏掉 https-proxy,Composer 就会静默 fallback 到直连——没报错,但所有 HTTPS 请求都超时或返回 502。
https-proxy 的值必须是 http:// 开头
这是 Composer 的硬性约定:哪怕你的代理服务监听的是 TLS 端口(如 443),https-proxy 的值也必须写成 http://127.0.0.1:8080,不能是 https://,也不能省略协议头。
- 错误写法:
https://127.0.0.1:8080、127.0.0.1:8080、socks5://127.0.0.1:1080 - 正确写法:
http://127.0.0.1:8080(带认证则为http://user:pass@127.0.0.1:8080) - 密码含
@、/、:必须 URL 编码,例如pa@ss/word→pa%40ss%2Fword,可用php -r "echo rawurlencode('pa@ss/word');"快速生成
必须加 -g 参数,否则换目录就失效
不加 -g(即 --global)时,composer config http-proxy ... 只写入当前项目下的 composer.json,对全局无效。真正生效的配置必须写入全局配置文件(%APPDATA%\Composer\config.json 或 ~/.composer/config.json)。
- 正确命令:
composer config -g http-proxy http://127.0.0.1:8080和composer config -g https-proxy http://127.0.0.1:8080 - 验证是否写入成功:
composer config -g --list | grep -E "(http|https)-proxy",应输出两行且格式正确 - Windows 下若报
Could not write to file,检查%APPDATA%\Composer目录是否存在且当前用户有写权限
镜像和代理不能共存
二者作用机制冲突:repo.packagist 镜像改的是请求地址(比如指向阿里云镜像站),而 http-proxy/https-proxy 改的是流量出口路径。同时配置会导致 Composer 完全忽略代理字段——日志里看不到 Proxy CONNECT,但 composer install -n -vvv 明明卡住。
- 想用代理,第一步必须清空镜像:
composer config -g --unset repo.packagist - 企业内网即使用了镜像,只要强制 HTTPS 流量过代理,没配
https-proxy一样连不上 - NTLM 代理(如 Windows 域环境)无法被 Composer 原生支持,填了
http-proxy也会直接返回407 Proxy Authentication Required;必须用cntlm或px在本地起中转,再让 Composer 连http://127.0.0.1:3128
https-proxy”、“有没有加 -g”、“有没有残留镜像”。这三个点任意一个出错,都会表现为“绑了但没用”,且无明确报错。


















