链接服务器后,如何在服务端走翻墙代理

17 天前
 faoisdjioga

装了 codex ,本地通过如下方法可以使用代理,然后使用 codex

export HTTP_PROXY="socks5://127.0.0.1:1080"
export HTTPS_PROXY="socks5://127.0.0.1:1080"
code &

我的使用场景是需要链接服务器,在服务端挂载这个代理呢?

1352 次点击
所在节点    Visual Studio Code
10 条回复
jayeli
17 天前
ssh 端口映射? ssh -N -R
faoisdjioga
17 天前
@jayeli 服务端我也挂了代理服务,我想要是的如何让在服务端的 codex 插件使用这个代理。

目前情况上,在通过 remote ssh 链接到服务端之后,服务端的 codex 插件好像用不了。
aarones
17 天前
试一下把这个代理环境变量加到/etc/profile 下面,改好再重新连接
faoisdjioga
17 天前
# 1. Create a global proxy agent file
mkdir -p ~/.vscode-server/extensions
cat > ~/.vscode-server/extensions/proxy-agent.js <<'EOF'
const { setGlobalDispatcher, ProxyAgent } = require('undici');
const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
if (proxy) {
console.log('[VSCode Proxy] Using proxy:', proxy);
setGlobalDispatcher(new ProxyAgent(proxy));
}
EOF


# 2. Export proxy and Node options globally
echo 'export HTTP_PROXY="socks5://127.0.0.1:1080"' >> ~/.bashrc
echo 'export HTTPS_PROXY="socks5://127.0.0.1:1080"' >> ~/.bashrc
echo 'export NODE_OPTIONS="--require ~/.vscode-server/extensions/proxy-agent.js"' >> ~/.bashrc
source ~/.bashrc


因为没有 root ,chatgpt 给了我一个方式成功了。chatgpt 的解释为

🧠 1. What the problem really was

When you run VS Code Remote SSH, the “editor” part runs on your Mac,
but the extensions (ChatGPT, Copilot, Supermaven, R, etc.) run on the remote Linux server inside a Node.js process called the extension host:

VSCode (Mac)
└── SSH tunnel
└── vscode-server (Ubuntu)
└── node --type=extensionHost
└── openai.chatgpt-0.4.19-linux-x64


That Node process makes its own outbound HTTPS calls (to api.openai.com, etc.).
By default, it doesn’t inherit your system or VS Code proxy because:

VS Code starts that process with --useHostProxy=false (no host proxy forwarding)

Node’s internal HTTP client ignores http.proxy from VS Code settings

Therefore → all extension network traffic bypasses your proxy

So the ChatGPT / CodeX extension couldn’t reach the Internet unless the server itself had open access.
faoisdjioga
16 天前
用他,注意是在 Remote-Server
{
"http.proxy": "http://127.0.0.1:1080",
"http.proxyStrictSSL": false,
"http.systemCertificates": false
}
NickLuan
14 天前
服务器是国内的吗,会被检测吗
faoisdjioga
10 天前
@NickLuan 国外。走的 trojan-go
faoisdjioga
10 天前
@NickLuan 刚刚我理解错了。服务器是在国内。 代理是在国外。
NickLuan
10 天前
@faoisdjioga #8 对的,国内的服务器,我担心的是被服务器的运营商检测到,比如阿里腾讯的,检测到你在服务器上挂代理会不会被封掉
faoisdjioga
9 天前
@NickLuan 服务器是公司内部的计算服务器,因此没有您说的这个问题。运营商的服务器没有用过,不太清楚

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://ex.noerr.eu.org/t/1164832

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX