Skip to content

Instantly share code, notes, and snippets.

@RockDeng110
Created June 24, 2025 17:03
Show Gist options
  • Save RockDeng110/c2bf7950d9cd4a16bb879d5bb8f8bd17 to your computer and use it in GitHub Desktop.
Save RockDeng110/c2bf7950d9cd4a16bb879d5bb8f8bd17 to your computer and use it in GitHub Desktop.
# 使用 v2rayN 设置 HTTP 代理并解决 Webots 无法访问网络资源的问题

使用 v2rayN 设置 HTTP 代理并解决 Webots 无法访问网络资源的问题

📌 问题背景

在运行 Webots 仿真项目时,控制器 Python 脚本需要访问 https://raw.githubusercontent.com 等国外资源,而我位于中国,尽管能“翻墙”,但 Webots 无法正常下载资源,提示 404 或连接超时。

🎯 目标

通过配置 v2rayN 的 HTTP 代理功能,让 Webots 和其他命令行程序(如 curl, pip)能够使用代理访问外网。


🧩 故障表现

  • Webots 启动时报错:无法访问 raw.githubusercontent.com

  • PowerShell 中 curl 命令访问 Google 报错:

    curl: (7) Failed to connect to 127.0.0.1 port 10809: Connection refused

🧭 排查过程

✅ Step 1: 确认 v2rayN 正常翻墙

  • 打开 v2rayN,切换服务器节点,能浏览 Google/YouTube。
  • 系统设置中未生效 HTTP 代理,命令行依旧无法代理访问。

🔍 Step 2: 检查 v2rayN 的 HTTP 代理是否启用

操作路径:

在 v2rayN 界面中:

  • 右键点击正在使用的服务器节点

  • 选择:属性 (服务器配置)设置本地端口

  • 勾选并设置:

    • 本地 Socks 代理端口(通常为 10808
    • 本地 HTTP 代理端口(如 10809

配置结果:

此时 HTTP 代理端口应为 127.0.0.1:10809


🧪 Step 3: 使用 curl 测试 HTTP 代理是否工作

curl https://www.google.com --proxy http://127.0.0.1:10809
  • 初期返回错误:Connection refused
  • 查看 v2rayN 日志,发现 HTTP 请求 malformed,代理未监听 10809 端口
  • 检查实际 Xray 核心路径,发现 v2rayN 可能调用的是 ~/Downloads/.../v2rayN-windows-64/bin/xray/xray.exe,而非我以为的旧路径

🔧 Step 4: 手动运行 Xray 并指定 config

  1. 进入路径:

    ~/Downloads/v2rayN-windows-64-desktop/v2rayN-windows-64/bin
    
  2. 创建 myconfig.json 内容如下(简化版,仅启用 HTTP 和 Socks):

{
  "inbounds": [
    {
      "port": 10808,
      "listen": "127.0.0.1",
      "protocol": "socks",
      "settings": { "udp": true }
    },
    {
      "port": 10809,
      "listen": "127.0.0.1",
      "protocol": "http",
      "settings": {}
    }
  ],
  "outbounds": [
    {
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "your_server_address",
            "port": 12345,
            "users": [{ "id": "uuid", "alterId": 0 }]
          }
        ]
      }
    }
  ]
}
  1. 启动 Xray 手动运行该配置:
.\bin\xray\xray.exe run -c .\binConfigs\myconfig.json
  1. 验证是否成功:
curl https://www.google.com --proxy http://127.0.0.1:10809

🎉 出现 Google 页面 HTML 内容,说明 HTTP 代理生效!


🧰 附加技巧:一键启动批处理脚本

@echo off
setlocal

echo 启动 Xray 核心...
start "" /min "%~dp0\bin\xray\xray.exe" run -c "%~dp0\binConfigs\myconfig.json"

set http_proxy=http://127.0.0.1:10809
set https_proxy=http://127.0.0.1:10809

echo 启动 Webots...
start "" "C:\Program Files\Webots\msys64\mingw64\bin\webots.exe"

endlocal

✅ 最终结果

  • 成功启用 v2rayN 的 HTTP 代理功能
  • curl, pip, Webots 等命令均可通过 HTTP 代理访问外网资源
  • 问题解决 ✅

🧠 总结

环节 关键操作
识别核心 查明 v2rayN 实际调用的 Xray 路径
启用 HTTP 代理 修改配置或手动启动核心并监听 10809 端口
验证代理功能 使用 curl --proxy 测试访问 Google
自动化启动 编写 .bat 脚本一键设置代理 + 启动 Webots

如果你希望我将这份文档导出为 Markdown 或 PDF,也可以告诉我。是否需要?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment