XTLS / Xray-core

Xray, Penetrates Everything. Also the best v2ray-core, with XTLS support. Fully compatible configuration.
https://t.me/projectXray
Mozilla Public License 2.0
24.42k stars 3.82k forks source link

VLESS-gRPC 报503,始终无法连通(已自行解决,内附方案) #510

Closed Nehcknarf closed 3 years ago

Nehcknarf commented 3 years ago

容器间不能使用 127.0.0.1 通讯

修改了新一版的配置,容器内可以相互ping通,但是客户端还是报503,求助各位大佬。 VPS防火墙是开放的,容器时区也已经同步,两容器日志均无异常记录(日志在原issue) 配置开启了multiMode 容器执行命令:

docker run -d --name caddy --network=my-net --restart=always \
    -v /etc/caddy/Caddyfile:/etc/caddy/Caddyfile \
    -v /etc/caddy/data:/data \
    -v /etc/caddy/config:/config \
    -p 80:80 -p 443:443 \
    caddy caddy file-server --domain x.cyou
docker run -d --name xray --network=my-net --restart=always \
    -v /etc/xray:/etc/xray \
    -p 2002:2002 \
    teddysun/xray

Caddyfile配置:

x.cyou {
    @grpc {
        protocol grpc
        path /Neo/*
    }
    reverse_proxy @grpc h2c://xray:2002
    root * /var/www
    file_server
}

服务器配置:

{
  "log": {
    "loglevel": "warning"
  },
  "inbounds": [
    {
      "port": 2002,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "id": "3065xxxx-xxxx-xxxx-xxxx-xxxx2c78af8e"
          }
        ],
        "encryption": "none"
      },
      "streamSettings": {
        "network": "grpc",
        "grpcSettings": {
          "serviceName": "Neo",
          "multiMode": true
        }
      }
    }
  ],
  "outbounds": [
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {}
    },
    {
      "tag": "blocked",
      "protocol": "blackhole",
      "settings": {}
    }
  ],
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "blocked"
      }
    ]
  }
}

客户端配置: QQ截图20210411202746

Originally posted by @Nehcknarf in https://github.com/XTLS/Xray-core/issues/483#issuecomment-817299919

Ariesly commented 3 years ago

h2c://xray:2002 改成 grpc://xray:2002 试试 不行就换成 nginx

location /Neo {
    grpc_pass grpc://xray:2002;
}

我就是caddy2配置没成功,换成nginx的.

Nehcknarf commented 3 years ago

h2c://xray:2002 改成 grpc://xray:2002 试试 不行就换成 nginx

location /Neo {
    grpc_pass grpc://xray:2002;
}

我就是caddy2配置没成功,换成nginx的.

成功了!虽然不是你说的问题,但是还是很感谢。你可以试下我的caddy方案。

docker run -d --name caddy --network=my-net --restart=always \
    -v /etc/caddy/Caddyfile:/etc/caddy/Caddyfile \
    -v /etc/caddy/data:/data \
    -v /etc/caddy/config:/config \
    -p 80:80 -p 443:443 \
    caddy

较之前的版本删去了多余的指令

docker run -d --name xray --network=my-net --restart=always \
    -v /etc/xray:/etc/xray \
    teddysun/xray

xray容器可以无需端口映射

x.cyou {
    @grpc {
        protocol grpc
        path /Neo/*
    }
    reverse_proxy @grpc h2c://xray:2002
    root * /var/www
    file_server
}

Caddyfile不变

{
  "log": {
    "loglevel": "warning"
  },
  "inbounds": [
    {
      "port": 2002,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "id": "xxxxxxxx"
          }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "grpc",
        "grpcSettings": {
          "serviceName": "Neo",
          "multiMode": true
        }
      }
    }
  ],
  "outbounds": [
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {}
    },
    {
      "tag": "blocked",
      "protocol": "blackhole",
      "settings": {}
    }
  ],
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "blocked"
      }
    ]
  }
}

xray服务端配置不变

{
  "log": {},
  "inbounds": [
    {
      "port": "10808",
      "protocol": "socks",
      "settings": {
        "auth": "noauth",
        "udp": true
      }
    },
    {
      "port": "10809",
      "protocol": "http",
      "settings": {}
    }
  ],
  "outbounds": [
    {
      "protocol": "vless",
      "settings": {
        "vnext": [
          {
            "address": "x.xxx",
            "port": 443,
            "users": [
              {
                "id": "xxxxxxx",
                "encryption": "none"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "grpc",
        "security": "tls",
        "grpcSettings": {
          "serviceName": "Neo"
        }
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {}
    },
    {
      "tag": "blocked",
      "protocol": "blackhole",
      "settings": {}
    }
  ],
  "routing": {
    "domainStrategy": "IPOnDemand",
    "rules": [
      {
        "type": "field",
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "direct"
      }
    ]
  }
}

客户端serviceName暂时只保留 Neo,因为我用的V2rayN 4.13版本会自动在后面补/Tun,所以/TunMulti暂时不可用,别的客户端可以配置TunMulti