server
使用官方安装脚本
curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh -o install-release.sh
sudo bash install-release.sh生成uuid
v2ray uuid修改配置文件
sudo nano /usr/local/etc/v2ray/config.json{
"log": {
"loglevel": "warning"
},
"inbounds": [
{
"port": 80, // 监听端口,例如 80 (HTTP默认端口)
"listen": "0.0.0.0", // 监听所有网络接口,允许外部连接
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "YOUR_UUID", // 替换为您的UUID,务必生成一个新的UUID
"alterId": 0 // 推荐设为0
}
]
},
"streamSettings": {
"network": "ws", // 使用 WebSocket 传输
"security": "none", // 明确不使用 TLS 安全
"wsSettings": {
"path": "/your_websocket_path", // 替换为您的 WebSocket 路径,例如 /ray
"headers": {
"Host": "www.bing.com" // 伪装成访问 bing.com,可以替换为其他常见网站
}
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
},
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"routing": {
"rules": [
{
"type": "field",
"ip": [
"geoip:private"
],
"outboundTag": "blocked"
}
]
}
}client
{
"inbounds": [
// --- 1. 服务端入站配置 (供其他V2Ray客户端连接此机器) ---
// 示例:VMess + WebSocket + TLS
{
"port": 443, // 这是一个公共端口,确保你的防火墙已打开此端口
"listen": "0.0.0.0", // 监听所有网络接口
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "YOUR_SERVER_UUID", // 为本机V2Ray服务端生成一个新的UUID
"alterId": 0
}
]
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"serverName": "YOUR_DOMAIN.COM", // 替换为你的域名
"certificates": [
{
"certificateFile": "/etc/v2ray/fullchain.pem", // 你的TLS证书路径
"keyFile": "/etc/v2ray/privkey.pem" // 你的TLS私钥路径
}
]
},
"wsSettings": {
"path": "/your_websocket_path" // WebSocket路径,可自定义
}
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"tag": "server_inbound" // 标记此入站连接为服务端
},
// --- 2. 客户端入站配置 (供本机应用程序使用) ---
// 本地SOCKS5代理
{
"port": 1080, // 本地监听端口
"listen": "127.0.0.1",
"protocol": "socks",
"settings": {
"udp": true
},
"tag": "client_socks_in" // 标记此入站连接为客户端SOCKS5
},
// 本地HTTP代理 (如果需要)
{
"port": 1081, // 本地监听端口
"listen": "127.0.0.1",
"protocol": "http",
"settings": {
"timeout": 300
},
"tag": "client_http_in" // 标记此入站连接为客户端HTTP
}
],
"outbounds": [
// --- 1. 客户端出站配置 (连接到你的远程V2Ray服务器) ---
// 示例:VMess
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "REMOTE_SERVER_IP_OR_DOMAIN", // 你的远程V2Ray服务器IP或域名
"port": REMOTE_SERVER_PORT, // 远程V2Ray服务器端口
"users": [
{
"id": "REMOTE_SERVER_UUID", // 远程V2Ray服务器的UUID
"alterId": 0
}
]
}
]
},
"tag": "proxy_outbound" // 标记此出站连接为代理
},
// --- 2. 服务端出站配置 / 直连出站 (供本机V2Ray服务端直连互联网,或本机直连流量) ---
{
"protocol": "freedom",
"tag": "direct_outbound", // 标记此出站连接为直连
"settings": {}
},
// --- 3. 流量阻断出站 (可选,用于广告过滤等) ---
{
"protocol": "blackhole",
"tag": "block_outbound",
"settings": {
"response": {
"type": "http" // 或 "dns", 根据需要选择
}
}
}
],
"routing": {
"domainStrategy": "IPOnDemand",
"rules": [
// 规则1: 阻止广告和恶意网站 (需要导入geosite:category-ads等)
{
"type": "field",
"domain": ["geosite:category-ads", "geosite:category-malware"],
"outboundTag": "block_outbound"
},
// 规则2: 私有IP地址直连
{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "direct_outbound"
},
// 规则3: 任何来自"server_inbound"的流量 (其他客户端连接到本机) 走直连
{
"type": "field",
"inboundTag": ["server_inbound"],
"outboundTag": "direct_outbound"
},
// 规则4: 任何来自"client_socks_in"或"client_http_in"的流量 (本机应用程序) 走代理
{
"type": "field",
"inboundTag": ["client_socks_in", "client_http_in"],
"outboundTag": "proxy_outbound"
}
]
},
"dns": {
"servers": [
"8.8.8.8", // Google DNS
"8.8.4.4",
"localhost"
]
}
}重启
sudo service v2ray restart