发布于2026-07-02 阅读(0)
扫一扫,手机访问
GitHub Enterprise 私有仓库拉不下来?别急着怀疑 token 配错了,大概率是 github-domains 这个白名单压根就没加。Composer 默认只认 api.github.com,其他域名全被静默跳过,连认证流程都走不到。
先说一个核心判断:Composer 2.2+ 搞的这个 github-domains,本质上就是一个白名单机制——只有列在里面的域名,Composer 才会正眼看一下,走 GitHub API 认证流程。没进白名单的域名(比如你企业的 git.example.com),哪怕 auth.json 里 token 写得再漂亮、repositories 也指向了地址,该报 Could not fetch 还是报,该卡在 Reading composer.json 还是卡。
很多人的错觉是“我 token 都配好了,怎么还 401”,其实根本没走到认证那步。这才是问题的关键所在。
配置的时候有几个细节要注意:github-domains 必须是字符串数组,每个元素只能是纯域名(比如 "git.example.com"),不能带 https://、端口号或者路径。子路径不影响匹配——https://git.example.com/github 这种情况,只需要填 "git.example.com" 即可。配置可以放在全局(~/.composer/config.json),也可以放在项目级(composer.json 的 config 段),但项目级会覆盖全局设置。
composer config 命令怎么写才稳妥别手写 JSON,用命令行写入最靠谱。域名必须和实际 API 请求的 Host 完全一致,大小写敏感,不含协议头:
composer config -g github-domains '["git.example.com", "ghes.internal"]'composer config github-domains '["git.example.com"]'composer config -g --list | grep github-domains,能看到对应数组才算成功composer config -g --unset github-domainsWindows 用户注意了,PowerShell 中单引号内不能插变量,建议用 CMD 或者直接粘贴完整字符串。
光加域名只是开了门,后面几步漏一个,照样进不去:
auth.json 里得有对应域名的 token:{"github-oauth": {"git.example.com": "ghp_abc123"}}(token 必须在 GHE 实例上生成,且勾选 repo 权限)composer.json 的 repositories 必须显式声明类型为 vcs,URL 用完整 HTTPS 地址:{"type": "vcs", "url": "https://git.example.com/owner/repo.git"}最后一步,清缓存:composer clear-cache,再跑 composer install。GHE 的 API 路径可能不是 /api/v3,但只要域名进了 github-domains 白名单,Composer 就会自动适配。
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
8