VSCode 远程 Linux 使用Codex

原理:远程服务器无法直接使用本地网络环境进而使用Codex,因此需要借助 SSH 的端口转发机制,将远程机器的网络请求通过安全隧道转发到本地上,从而让远程服务器间接复用本地的网络访问能力。

1.查看本地加速器的端口号,我这里是10090

2. Windows打开Powershell, 本地确认加速器端口

复制代码
curl.exe https://chatgpt.com --proxy http://127.0.0.1:10090

能返回如下内容说明加速器正常,返回异常说明本地加速器端口错误


3. 开启加速器允许局域网访问

在加速器软件中开启:

  • Allow LAN / 允许局域网连接

4. VSCode 连接远程 Linux

Remote-SSH 连接服务器,在对应的远程机器下添加如下:

bash 复制代码
  Host Host1
    HostName 1.1.1.1
    User host
    Port 11
    RemoteForward 9999 127.0.0.1:10090
    ServerAliveInterval 60
    ServerAliveCountMax 3

RemoteForward:把你本地的加速器端口转发到远程 Linux 上使用,这里是把本地的10090端口转发到Linux中的9999端口

ServerAliveInterval:每隔一段时间发送心跳,防止 SSH 断线。

ServerAliveCountMax:心跳失败多少次后才真正断开连接。


5. 配置远程的settings.json

(1)远程 VSCode 按 Ctrl + Shift + P

(2)搜索:Preferences: Open Remote Settings (JSON)

(3)点击打开,自动跳转到远程配置文件

在最下面写入如下,按照自己之前配置的写

bash 复制代码
     // 远程VSCode加速器地址(SSH转发的远程端口)
    "http.proxy": "http://127.0.0.1:9999",
     // 本地地址不走加速器,避免冲突
    "http.noProxy": "localhost,127.0.0.1,::1",
     // 强制开启加速器支持
    "http.proxySupport": "on"

6. 终端用加速器(可选)

终端输入如下,一句一句执行

bash 复制代码
echo 'export HTTP_PROXY=http://127.0.0.1:9999' >> ~/.bashrc
echo 'export HTTPS_PROXY=http://127.0.0.1:9999' >> ~/.bashrc
echo 'export http_proxy=http://127.0.0.1:9999' >> ~/.bashrc
echo 'export https_proxy=http://127.0.0.1:9999' >> ~/.bashrc
source ~/.bashrc

7. 验证

bash 复制代码
curl -I -m 10 -x http://127.0.0.1:9999  https://chatgpt.com/

输出如下,即加速器成功:

相关推荐
AlfredZhao11 小时前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
戴为沐2 天前
Linux内存扩容指南
linux
zylyehuo2 天前
Linux 彻底且安全地删除文件
linux
用户805533698033 天前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式
用户034095297913 天前
linux fcitx 5 雾凇拼音 设置在中文输入法下仍然输入英文标点
linux
Web3探索者4 天前
可视化服务器管理和传统命令行区别是什么?新手教程:Linux 运维到底该用图形界面还是 SSH 命令行?
linux·ssh
zylyehuo4 天前
Linux系统中网线与USB网络共享冲突
linux
Sokach10156 天前
Linux Shell 脚本从零到能用:一个新手的一天学习总结
linux
AlfredZhao6 天前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
zzzzzz3108 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql