GitHub Copilot 网络代理配置与优化指南
在使用 GitHub Copilot 时,开发者常遇到因网络策略或区域限制导致的服务激活失败。通过合理的代理配置和网络环境调整,可以有效解决连接问题,确保代码补全功能稳定运行。
本地代理服务器配置
为了让 Copilot 顺利连接远程 API,在本地部署 HTTP 代理服务是一个常见方案。下面是一个基于 Node.js 的简易代理示例:
// proxy-server.js
const http = require('http');
const net = require('net');
// 创建 HTTP 代理服务器
const server = http.createServer((req, res) => {
// 允许跨域请求
res.setHeader('Access-Control-Allow-Origin', '*');
res.end('Proxy active for Copilot');
});
// 监听 8080 端口
server.listen(8080, () => {
console.log('Proxy server running on http://localhost:8080');
});
启动服务后,需要在 IDE 的网络设置中指定代理地址。以 VS Code 为例:
- 打开设置(Ctrl + ,)。
- 搜索
proxy。 - 填写代理地址:
http://127.0.0.1:8080。
修改 Hosts 文件绕过 DNS 限制
部分网络环境会屏蔽 Copilot 的核心域名,手动绑定 IP 可以解决解析失败的问题。
- Windows 路径:
C:\Windows\System32\drivers\etc\hosts - macOS/Linux 路径:
/etc/hosts
添加如下条目:
# GitHub Copilot 域名解析
140.82.113.6 api.github.com
140.82.113.6 copilot-proxy.githubusercontent.com
验证网络连通性
执行以下命令测试代理是否生效:
curl -x http://127.0.0.1:8080 -I https://copilot-proxy.githubusercontent.com
若返回状态码 200,表示代理配置成功。

