V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
faoisdjioga
V2EX  ›  Visual Studio Code

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

  •  
  •   faoisdjioga · 10 天前 · 1151 次点击

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

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

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

    第 1 条附言  ·  3 天前
    继续跪求一个方法~

    之前测试了一些方法,一开始可以用。不知道为什么在服务端又好用了。在本地可以。

    自己编程常用 vscode ,但是对 vscode 配置了解非常少。求一个标准的配置方法
    10 条回复    2025-10-21 10:28:28 +08:00
    jayeli
        1
    jayeli  
       10 天前
    ssh 端口映射? ssh -N -R
    faoisdjioga
        2
    faoisdjioga  
    OP
       10 天前
    @jayeli 服务端我也挂了代理服务,我想要是的如何让在服务端的 codex 插件使用这个代理。

    目前情况上,在通过 remote ssh 链接到服务端之后,服务端的 codex 插件好像用不了。
    aarones
        3
    aarones  
       10 天前
    试一下把这个代理环境变量加到/etc/profile 下面,改好再重新连接
    faoisdjioga
        4
    faoisdjioga  
    OP
       10 天前
    # 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
        5
    faoisdjioga  
    OP
       9 天前
    用他,注意是在 Remote-Server
    {
    "http.proxy": "http://127.0.0.1:1080",
    "http.proxyStrictSSL": false,
    "http.systemCertificates": false
    }
    NickLuan
        6
    NickLuan  
       7 天前
    服务器是国内的吗,会被检测吗
    faoisdjioga
        7
    faoisdjioga  
    OP
       3 天前
    @NickLuan 国外。走的 trojan-go
    faoisdjioga
        8
    faoisdjioga  
    OP
       3 天前
    @NickLuan 刚刚我理解错了。服务器是在国内。 代理是在国外。
    NickLuan
        9
    NickLuan  
       3 天前
    @faoisdjioga #8 对的,国内的服务器,我担心的是被服务器的运营商检测到,比如阿里腾讯的,检测到你在服务器上挂代理会不会被封掉
    faoisdjioga
        10
    faoisdjioga  
    OP
       2 天前
    @NickLuan 服务器是公司内部的计算服务器,因此没有您说的这个问题。运营商的服务器没有用过,不太清楚
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2845 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:37 · PVG 21:37 · LAX 06:37 · JFK 09:37
    ♥ Do have faith in what you're doing.