v2rayN HTTP Proxy Setup, LAN Sharing, and Cloud Relay with Socat

  1. Load an HTTP proxy into v2rayN and use it as an upstream.
  2. Share v2rayN to LAN devices that only support HTTP proxy (convert v2rayN SOCKS5 → LAN HTTP).
  3. In Mainland China, some upstream proxies are not directly reachable. Use an overseas cloud VM (Google Cloud example) + socat to relay v2rayN’s outgoing/upstream traffic (the traffic v2rayN sends to the upstream proxy), so v2rayN can still use that proxy.

Quick Summary

If your upstream proxy is reachable, you only need the first section. If you want phones/TV boxes/other PCs on the same Wi-Fi to use it, add the LAN sharing section. If you’re in Mainland China and your upstream proxy connection times out or fails, use the cloud relay section as the “Plan B” after you followed the first section but still can’t connect.

如果你的上游代理能直连,那么只需要第一部分。如果你要让同一局域网里的手机/电视盒子/其他电脑也能用,再加第二部分。如果你在中国大陆遇到“上游代理直连不上”(超时、握手失败、路由黑洞等),那就按第三部分用海外云服务器中转——这是第一部分照做仍然连不上的补救方案。

Prerequisites

Prepare your upstream proxy information: PROXY_HOST, PROXY_PORT, and optional username/password. Also note v2rayN local SOCKS5 port (commonly 127.0.0.1:10808). For LAN sharing you’ll use Privoxy. For cloud relay you’ll need an overseas VM public IP.

准备好你的上游代理信息:代理地址、代理端口、以及可能的用户名/密码。同时确认 v2rayN 的本地 SOCKS5 端口(常见 127.0.0.1:10808)。局域网分享需要 Privoxy;云中转需要一台海外云服务器和公网 IP。

Part 1 — Load an HTTP Proxy into v2rayN

Add an HTTP Server Entry

Open v2rayN → ServersAdd server → choose HTTP (or “Add [HTTP] server”). Fill in the fields and save. Then set it as the active server (double-click or right-click).

打开 v2rayN → 服务器添加服务器 → 选择 HTTP(有的版本写“添加[HTTP]服务器”)。填好信息保存后,把它设为当前活动节点(双击或右键设置)。

Enable System Proxy and Test

Enable System Proxy in v2rayN and choose a mode (Global/Rule/PAC depending on your build). For first-time testing, use Global, open a browser, and check whether sites work and IP changes as expected.

v2rayN 里开启系统代理,选择模式(全局/规则/PAC 视版本而定)。首次测试建议先用全局,打开浏览器访问常用网站或查 IP,确认是否生效。

Common Failure (Why Part 3 Exists)

If you followed the steps but v2rayN still cannot connect to that HTTP proxy, it’s often not a config typo—it can be a network reachability issue (especially in Mainland China). The cloud relay section is designed as the fix for “added correctly but cannot reach upstream proxy.”

如果你按步骤添加了,但 v2rayN 还是连不上那个 HTTP 代理,很多时候并不是你填错,而是网络层面根本路由不到(中国大陆很常见)。第三部分就是专门解决“配置没问题但直连不上上游代理”的。

Part 2 — Convert v2rayN SOCKS5 to a LAN-Accessible HTTP Proxy

Goal: LAN devices point to your PC’s LAN IP + an HTTP port, then Privoxy forwards to v2rayN local SOCKS5, and v2rayN forwards upstream.

目标是:局域网设备把 HTTP 代理指向“你电脑的局域网 IP + 一个 HTTP 端口”,Privoxy 把流量转到 v2rayN 的本地 SOCKS5,再由 v2rayN 出站。

Confirm v2rayN Local SOCKS5 Port

Check v2rayN settings for its local SOCKS port (commonly 127.0.0.1:10808). Make sure v2rayN itself works first.

在 v2rayN 参数设置里确认本地 SOCKS 端口(常见 127.0.0.1:10808)。务必先确保 v2rayN 本机可用。

Privoxy Core Config (Copy/Paste)

Choose a neutral LAN HTTP port like 18080 (avoid confusing ports). Privoxy will listen on LAN and forward everything to v2rayN SOCKS5.

选一个不容易误会的端口,比如 18080(避免 8118 这类容易让人联想到“某种默认 HTTP 代理端口”的数字)。Privoxy 监听局域网 HTTP 端口,把全部流量转到 v2rayN 的本地 SOCKS5。

# Listen on LAN (HTTP proxy port)
listen-address  0.0.0.0:18080

# Forward EVERYTHING to v2rayN local SOCKS5
forward-socks5t   /   127.0.0.1:10808 .

Windows Setup

Install Privoxy, locate its config file, paste the config above, restart Privoxy, then allow inbound TCP 18080 on Private network.

安装 Privoxy,找到配置文件,把上面两段核心配置写进去,重启 Privoxy,然后在 Windows 防火墙放行入站 TCP 18080(建议只放行 Private 网络)。

# Allow inbound TCP 18080 (Private network only)
New-NetFirewallRule -DisplayName "LAN HTTP Proxy 18080" `
  -Direction Inbound -Protocol TCP -LocalPort 18080 -Action Allow -Profile Private

Linux Setup (Debian/Ubuntu)

Install Privoxy, edit /etc/privoxy/config, restart and enable the service. If you use UFW, allow the port.

安装 Privoxy,编辑 /etc/privoxy/config,重启并设置开机自启。如果你启用了 UFW,再放行端口。

sudo apt update
sudo apt install -y privoxy
sudo nano /etc/privoxy/config
sudo systemctl restart privoxy
sudo systemctl enable privoxy
# If UFW is enabled
sudo ufw allow 18080/tcp

macOS Setup (Homebrew)

Install Privoxy via Homebrew, edit the config file, restart the service. macOS firewall is app-based—allow inbound when prompted.

用 Homebrew 安装 Privoxy,编辑配置文件,然后重启服务。macOS 防火墙偏应用放行,如果提示允许入站连接请选择允许。

brew install privoxy
nano /opt/homebrew/etc/privoxy/config
brew services restart privoxy

LAN Device Proxy Settings

Find your PC’s LAN IP (example 192.168.1.10). On your phone/TV/other PC, set HTTP proxy to 192.168.1.10:18080.

查到你电脑的局域网 IP(例如 192.168.1.10)。在手机/电视盒子/其他电脑里设置 HTTP 代理为 192.168.1.10:18080。

Part 3 — Cloud Relay for Mainland China Using Google Cloud + socat

This part is the “Plan B” when Part 1 is configured correctly but the upstream proxy is unreachable from Mainland China.
Relay target: the upstream connection that v2rayN makes (v2rayN’s outgoing traffic to the upstream proxy).
Not: v2rayN → Privoxy chaining.

这一部分是“救援方案”:当第一部分按步骤设置正确但在中国大陆就是连不上上游代理时,用它来绕路。中转的对象是:v2rayN 发往上游代理的连接/流量(也就是 v2rayN 的输出/获取的流量)。
不是:写成 v2rayN → Privoxy 的那条链路。

Concept and Flow

You will run socat on an overseas VM. It listens on CLOUD_PORT (example 20080) and forwards raw TCP to the real upstream proxy PROXY_HOST:PROXY_PORT. Then in v2rayN, you replace the upstream proxy host/port with CLOUD_IP:20080. From v2rayN’s perspective, it can now reach “the proxy endpoint” (the cloud), and the cloud completes the hard route to the real proxy.

你会在海外云服务器上运行 socat:它监听 云端口(示例 20080),把 TCP 流量转发到真实上游代理 代理地址:代理端口。然后你在 v2rayN 里把原来的上游代理地址改成 云IP:20080。对 v2rayN 来说,它能连上的“代理端点”变成云服务器,而云服务器替你完成到真实代理的连接。

Create a Google Cloud VM (Minimal Requirements)

Create a small Debian/Ubuntu VM with a public IPv4 and SSH access. The relay port must be restricted with firewall rules so it is not exposed to the entire internet.

创建一台 Debian/Ubuntu 的小 VM,确保有公网 IPv4 并能 SSH 登录。中转端口务必用防火墙限制来源,不要全网开放。

Install socat on the VM

sudo apt update
sudo apt install -y socat

Start the Relay (Test Mode)

Pick a relay port like 20080. Replace PROXY_HOST and PROXY_PORT with your real upstream proxy endpoint.

选择一个中性端口比如 20080。把 PROXY_HOST、PROXY_PORT 换成你的真实上游代理地址与端口。

sudo socat TCP-LISTEN:20080,reuseaddr,fork TCP:PROXY_HOST:PROXY_PORT

Make It Persistent with systemd

Create a service file so socat survives reboot.

写一个 systemd 服务文件,让 socat 重启后也自动运行。

# /etc/systemd/system/v2rayn-upstream-relay.service
[Unit]
Description=v2rayN upstream relay via socat
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
Restart=always
RestartSec=2
ExecStart=/usr/bin/socat TCP-LISTEN:20080,reuseaddr,fork TCP:PROXY_HOST:PROXY_PORT

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now v2rayn-upstream-relay
sudo systemctl status v2rayn-upstream-relay --no-pager

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注