Day Background Night Background
SSH 反向隧道代理配置

SSH 反向隧道代理配置

原理

VS Code 端口转发方向错误(服务器→本地),需要用 SSH 反向隧道将本地代理暴露给服务器。

配置步骤

1. 建立反向隧道

在本地终端执行,保持此窗口开启:

ssh -R <远程端>:127.0.0.1:<本地代理端> <用户>@<服务器IP> -p <SSH端>

2. 配置代理环境变量

在远程服务器终端执行:

export http_proxy=http://127.0.0.1:<远程端口>
export https_proxy=http://127.0.0.1:<远程端口>

3. 验证

curl -I https://www.google.com

返回 HTTP/2 200 即成功。

注意事项

  • 反向隧道终端不能关闭,关闭即断开隧道
  • 每次重新连接后需重新执行步骤 1-3
  • 环境变量仅对当前 shell session 生效,不影响其他用户

SSH 反向隧道代理配置

https://ryanjxy123.github.io/post/share_somethings/env_configuration/reverse_tunnel/

Author
Ryanjxy
Published at
March 10, 2026
Copyright
Ryanjxy