v2ray / v2ray-core

A platform for building proxies to bypass network restrictions.
https://www.v2ray.com/
MIT License
45.44k stars 8.95k forks source link

caddy+h2+tls "failed to read request header > stream error: stream ID xxx; CANCEL" #2076

Closed MeowFET closed 4 years ago

MeowFET commented 4 years ago

提交 Issue 之前请先阅读 Issue 指引,然后回答下面的问题,谢谢。 除非特殊情况,请完整填写所有问题。不按模板发的 issue 将直接被关闭。 如果你遇到的问题不是 V2Ray 的 bug,比如你不清楚要如何配置,请使用Discussion进行讨论。

1) 你正在使用哪个版本的 V2Ray?(如果服务器和客户端使用了不同版本,请注明) 4.21.3 2) 你的使用场景是什么? 网页浏览、观看 YouTube 视频等 3) 你看到的不正常的现象是什么?(请描述具体现象,比如访问超时,TLS 证书错误等) V2Ray 服务启动一段时间后,客户端出现无法连接的情况,重启 V2Ray 后连接恢复正常 4) 你期待看到的正确表现是怎样的? V2Ray 启动后能持续正常工作 5) 请附上你的配置(提交 Issue 前请隐藏服务器端IP地址)。

服务器端配置:

    // 在这里附上服务器端配置文件
{
  "log": {
    "loglevel": "info",
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log"
  },
  "inbounds": [{
    "port": 20190,
    "listen": "127.0.0.1",
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "some uuid",
          "level": 1,
          "alterId": 64
        }
      ]
    },
    "streamSettings": {
      "network": "h2",
      "security": "tls",
      "httpSettings": {
        "path": "/bucket",
    "host": ["xxx.yyy.zzz"]
      },
      "tlsSettings": {
    "serverName": "xxx.yyy.zzz",
    "certificates": [
    {
      "certificateFile": "/etc/v2ray/cert.crt",
      "keyFile": "/etc/v2ray/cert.key"
    }
    ]
      }
    }
  }],
  "outbounds": [{
    "protocol": "freedom",
    "settings": {}
  },{
    "protocol": "blackhole",
    "settings": {},
    "tag": "blocked"
  }],
  "routing": {
    "rules": [
      {
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
      }
    ]
  }
}

客户端配置:

{
  "log": {
    "error": "",
    "loglevel": "info",
    "access": ""
  },
  "outbounds": [
    {
      "protocol": "vmess",
      "streamSettings": {
        "tlsSettings": {
          "serverName": "xxx.yyy.zzz",
          "allowInsecure": false
        },
        "security": "tls",
        "httpSettings": {
          "path": "/bucket",
          "host": [
            "xxx.yyy.zzz"
          ]
        },
        "network": "h2"
      },
      "tag": "agentout",
      "settings": {
        "vnext": [
          {
            "address": "xxx.yyy.zzz",
            "users": [
              {
                "id": "some uuid",
                "alterId": 64,
                "level": 1,
                "security": "none"
              }
            ],
            "port": 443
          }
        ]
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "AsIs",
        "redirect": "",
        "userLevel": 0
      }
    },
    {
      "tag": "blockout",
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "none"
        }
      }
    }
  ],
  "dns": {
    "servers": [
      ""
    ]
  },
  "routing": {
    "strategy": "rules",
    "settings": {
      "domainStrategy": "IPIfNonMatch",
      "rules": [
        {
          "outboundTag": "direct",
          "type": "field",
          "ip": [
            "geoip:cn",
            "geoip:private"
          ],
          "domain": [
            "geosite:cn",
            "geosite:speedtest"
          ]
        }
      ]
    }
  },
  "transport": {}
}

6) 请附上出错时软件输出的错误日志。在 Linux 中,日志通常在 /var/log/v2ray/error.log 文件中。

服务器端错误日志:

2019/12/02 08:55:01 [Info] [3838754925] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 389; CANCEL
2019/12/02 08:55:07 [Info] [3912041362] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 391; CANCEL
2019/12/02 08:55:11 [Info] [3770826762] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 393; CANCEL
2019/12/02 08:55:16 [Info] [1308767177] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 399; CANCEL
2019/12/02 08:55:16 [Info] [3995426864] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 397; CANCEL
2019/12/02 08:55:16 [Info] [3991594457] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 395; CANCEL
2019/12/02 08:55:21 [Info] [2455374023] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 369; CANCEL
2019/12/02 08:55:30 [Info] [3612578077] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 401; CANCEL
2019/12/02 08:55:30 [Info] [4280515873] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 403; CANCEL
2019/12/02 08:55:30 [Info] [1846036703] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 405; CANCEL
2019/12/02 08:55:31 [Info] [1588946313] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 407; CANCEL
2019/12/02 08:55:37 [Info] [3774176444] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 411; CANCEL
2019/12/02 08:56:11 [Info] [1913081805] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 413; CANCEL
2019/12/02 08:56:16 [Info] [1809757778] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 415; CANCEL
2019/12/02 08:56:26 [Info] [2333996337] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 417; CANCEL
2019/12/02 08:56:39 [Info] [4171362482] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 419; CANCEL
2019/12/02 08:56:39 [Info] [1146838814] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 423; CANCEL
2019/12/02 08:56:39 [Info] [625695323] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 421; CANCEL
2019/12/02 08:56:39 [Info] [2739784565] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 425; CANCEL
2019/12/02 08:56:39 [Info] [558061020] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 409; CANCEL
2019/12/02 09:05:31 [Info] [1226193380] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 311; CANCEL
2019/12/02 09:05:31 [Info] [2526464214] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/vmess/inbound: invalid request from 127.0.0.1:50220 > v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 171; CANCEL

客户端错误日志:

2019/12/02 22:11:33 [Info] v2ray.com/core/transport/internet/udp: failed to handle UDP input > io: read/write on closed pipe
2019/12/02 22:11:46 [Info] [888748416] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:11:46 [Info] [3280895938] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:11:46 [Info] [2052814815] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:11:47 [Info] [1767668478] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:11:48 [Info] [2968754233] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:11:49 [Info] [3623113930] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:11:57 [Info] [3622868858] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:11:58 [Info] [4161351635] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:11:59 [Info] [3665410282] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:12:12 [Info] [2147131559] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:12:13 [Info] [1380429388] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:12:17 [Info] [110920364] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:12:22 [Info] [2242320780] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:12:32 [Info] [1470336529] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:12:34 [Info] [960041049] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:12:34 [Info] [2344660237] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled
2019/12/02 22:12:35 [Info] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: connection ends > context canceled

7) 请附上访问日志。在 Linux 中,日志通常在 /var/log/v2ray/access.log 文件中。

2019/12/02 09:15:10 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 521; CANCEL
2019/12/02 09:15:13 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 545; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 473; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 553; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 547; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 465; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 501; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 511; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 537; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 535; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 471; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 449; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 503; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 531; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 549; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 461; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 489; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 469; CANCEL
2019/12/02 09:15:14 127.0.0.1:50220 rejected  v2ray.com/core/proxy/vmess/encoding: failed to read request header > stream error: stream ID 481; CANCEL

8) 其它相关的配置文件(Caddy 配置文件)

xxx.yyy.zzz
{
  log ./caddy.log

  proxy /bucket https://localhost:20190 {
    insecure_skip_verify
    header_upstream X-Forwarded-Proto "https"
    header_upstream Host "xxx.yyy.zzz"
  }
}
kslr commented 4 years ago

设置加密停止h2再测试

MeowFET commented 4 years ago

更改为 (caddy+tls) + ws,不加密,可以稳定使用。

考虑到在之前的配置下,V2Ray 刚启动时总是可用,过一段时间(比如半小时)后无法连接,重启 V2Ray 后(不重启前置 Web 服务器)又恢复正常。也许和 V2Ray 的 h2 实现有关?条件允许的情况下,建议尝试复现一下。

kingwilliam commented 4 years ago

您的caddy是否欠了电子证书?

MeowFET commented 4 years ago

您的caddy是否欠了电子证书?

感谢回复。Caddy 集成了 ACME,在默认的配置下会自动申请 SSL 证书并应用。我在 V2Ray 服务端配置文件中设定的证书是这一证书的软链接。

sparsebase commented 4 years ago

Caddy设置了证书,V2Ray的server就不用设置证书了吧?不然岂不是要加密两次?