V2ray-core: 一直报错 400 Bad Request > websocket: bad handshake

Created on 8 Jul 2019  ·  2Comments  ·  Source: v2ray/v2ray-core

1) 你正在使用哪个版本的 V2Ray?(如果服务器和客户端使用了不同版本,请注明)
V2Ray 4.19.1 (Let's Fly) Custom + CentOS6.10

2) 你的使用场景是什么?比如使用 Chrome 通过 Socks/VMess 代理观看 YouTube 视频。
Win7 + Firefox + v2RayN 访问Google.com

3) 你看到的不正常的现象是什么?(请描述具体现象,比如访问超时,TLS 证书错误等)
无法连接,客户端v2Ray一直报错400 Bad Request > websocket: bad handshake
服务器的v2ray日志级别已经设置为 debug,但没有任何日志出现。
nginx的日志access.log 一请求就提示 400,日志内容如下:

119.29.18.40 - - [08/Jul/2019:08:11:44 -0700] "GET /pray HTTP/1.1" 101 831131 "-" "Go-http-client/1.1" "-"
119.29.18.40 - - [08/Jul/2019:08:11:56 -0700] "GET /pray HTTP/1.1" 400 59 "-" "Go-http-client/1.1" "-"

4) 你期待看到的正确表现是怎样的?
配置好之后,能在电脑里访问Google网站。

5) 请附上你的配置(提交 Issue 前请隐藏服务器端IP地址)。

服务器端配置:

{
  "log": {
     "loglevel":"debug",
     "access":"/var/log/v2ray/access.log",
     "error":"/var/log/v2ray/error.log"
  },
  "inbounds": [{
    "port": 14637,
    "listen": "127.0.0.1",
    "protocol": "vmess",
    "streamSettings": {
    "network":"ws",
        "security":"tls",
        "tlsSettings": {
          "allowInsecure": true,
          "serverName":"vm.mysite.com"
    },
    "wsSettings":{
      "connectionReuse":true,
      "path":"/pray",
      "headers": {
        "Host":"vm.mysite.com"
        }
    }
    },  
    "settings": {
      "clients": [
        {
          "id": "uuid",
          "level": 1,
          "alterId": 64
        }
      ]
    }
  }],
  "outbounds": [{
    "protocol": "freedom",
    "settings": {}
  },{
    "protocol": "blackhole",
    "settings": {},
    "tag": "blocked"
  }],
  "routing": {
    "rules": [
      {
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
      }
    ]
  }
}


客户端配置:

{
  "log": {
    "access": "",
    "error": "",
    "loglevel": "debug"
  },
  "inbounds": [
    {
      "port": 2333,
      "listen": "127.0.0.1",
      "protocol": "socks",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      },
      "settings": {
        "auth": "noauth",
        "udp": true,
        "ip": null,
        "clients": null
      },
      "streamSettings": null
    }
  ],
  "outbounds": [
    {
      "tag": "proxy",
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "vm.mysite.com",
            "port": 443,
            "users": [
              {
                "id": "uuid",
                "alterId": 64,
                "email": "[email protected]",
                "security": "auto"
              }
            ]
          }
        ],
        "servers": null,
        "response": null
      },
      "streamSettings": {
        "network": "ws",
        "security": "tls",
        "tlsSettings": {
          "allowInsecure": true,
          "serverName": "vm.mysite.com"
        },
        "tcpSettings": null,
        "kcpSettings": null,
        "wsSettings": {
          "connectionReuse": true,
          "path": "/pray",
          "headers": {
            "Host": "vm.mysite.com"
          }
        },
        "httpSettings": null,
        "quicSettings": null
      },
      "mux": {
        "enabled": false
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {
        "vnext": null,
        "servers": null,
        "response": null
      },
      "streamSettings": null,
      "mux": null
    },
    {
      "tag": "block",
      "protocol": "blackhole",
      "settings": {
        "vnext": null,
        "servers": null,
        "response": {
          "type": "http"
        }
      },
      "streamSettings": null,
      "mux": null
    }
  ],
  "dns": null,
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": []
  }
}

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

服务器端错误日志: 没有错误信息,没记录

2019/07/08 08:27:54 [Debug] v2ray.com/core/app/log: Logger started
2019/07/08 08:27:54 [Warning] v2ray.com/core: V2Ray 4.19.1 started

客户端错误日志:

配置成功
Vmess-buyvm(vm***com:443)
启动服务(2019/7/8 23:29:02)......
V2Ray 4.18.0 (Po) 20190228
A unified platform for anti-censorship.
2019/07/08 23:29:02 [Debug] v2ray.com/core/app/log: Logger started
2019/07/08 23:29:02 [Warning] v2ray.com/core: V2Ray 4.18.0 started
2019/07/08 23:29:09 [Info] [64741972] v2ray.com/core/proxy/socks: TCP Connect request to tcp:69.171.239.11:443
2019/07/08 23:29:09 tcp:127.0.0.1:59579 accepted tcp:69.171.239.11:443 
2019/07/08 23:29:09 [Info] [64741972] v2ray.com/core/app/dispatcher: sniffed domain: www.google.com
2019/07/08 23:29:09 [Info] [64741972] v2ray.com/core/app/dispatcher: default route for tcp:www.google.com:443
2019/07/08 23:29:09 [Info] [64741972] v2ray.com/core/transport/internet/websocket: creating connection to tcp:vm.mysite.com:443
2019/07/08 23:29:11 [Info] [64741972] v2ray.com/core/transport/internet/websocket: creating connection to tcp:vm.mysite.com:443
2019/07/08 23:29:13 [Info] [64741972] v2ray.com/core/transport/internet/websocket: creating connection to tcp:vm.mysite.com:443
2019/07/08 23:29:16 [Info] [64741972] v2ray.com/core/transport/internet/websocket: creating connection to tcp:vm.mysite.com:443
2019/07/08 23:29:22 [Info] [64741972] v2ray.com/core/transport/internet/websocket: creating connection to tcp:vm.mysite.com:443
2019/07/08 23:29:25 [Warning] [64741972] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: failed to find an available destination > v2ray.com/core/common/retry: [v2ray.com/core/transport/internet/websocket: failed to dial WebSocket > v2ray.com/core/transport/internet/websocket: failed to dial to (wss://vm.mysite.com/pray): 400 Bad Request > websocket: bad handshake] > v2ray.com/core/common/retry: all retry attempts failed
2019/07/08 23:29:25 [Info] [64741972] v2ray.com/core/app/proxyman/inbound: connection ends > v2ray.com/core/proxy/socks: connection ends > v2ray.com/core/proxy/socks: failed to transport all TCP response > io: read/write on closed pipe

7) 请附上访问日志。在 Linux 中,日志通常在 /var/log/v2ray/access.log 文件中。
空白的没有记录

    // 在这里附上服务器端日志
   // 空白没有日志

8) 其它相关的配置文件(如 Nginx)和相关日志。

[root@buyvm v2ray]# tail -f /var/log/nginx/access.log 
19.29.108.149 - - [08/Jul/2019:08:32:54 -0700] "GET /pray HTTP/1.1" 400 59 "-" "Go-http-client/1.1" "-"
19.129.118.49 - - [08/Jul/2019:08:32:59 -0700] "GET /pray HTTP/1.1" 400 59 "-" "Go-http-client/1.1" "-"
19.129.118.49 - - [08/Jul/2019:08:33:02 -0700] "GET /pray HTTP/1.1" 400 59 "-" "Go-http-client/1.1" "-"
19.129.118.49 - - [08/Jul/2019:08:33:05 -0700] "GET /pray HTTP/1.1" 400 59 "-" "Go-http-client/1.1" "-"

9) 如果 V2Ray 无法启动,请附上 --test 输出。

通常的命令为 /usr/bin/v2ray/v2ray --test --config /etc/v2ray/config.json。请按实际情况修改。

[root@buyvm v2ray]# /usr/bin/v2ray/v2ray --test --config /etc/v2ray/config.json
V2Ray 4.19.1 (Let's Fly) Custom
A unified platform for anti-censorship.
Configuration OK.

10) 如果 V2Ray 服务运行不正常,请附上 journal 日志。
通常的命令为 journalctl -u v2ray

11) nginx配置信息

{
    listen 80;
    server_name vm.mysite.com;
    add_header Strict-Transport-Security max-age=15768000 ;
    return 301 https://$server_name$request_uri ;
}


server {
    listen 443 ssl;
    server_name vm.mysite.com;

    root /htdocs/proxy/web;
    index index.html index.htm index.php

    ssl on;
    ssl_certificate /etc/letsencrypt/live/vm.mysite.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/vm.mysite.com/privkey.pem;


    location /pray {
        proxy_redirect off;
        proxy_pass http://127.0.0.1:14637;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

请预览一下你填的内容再提交。

Most helpful comment

你的 server 有这一段
streamSettings": {
"network":"ws",
"security":"tls",
"tlsSettings": {
"allowInsecure": true,
"serverName":"vm.mysite.com"
},

你的 nginx 有这一段
location /pray {
proxy_redirect off;
proxy_pass http://127.0.0.1:14637

这对配接有点问题,nginx用http问 127. 0.0.1:14637, 但v2ray 就用tls代接。

试试server只保留以下指令
"streamSettings": {
"network":"ws",
//刪除 tls部分
"wsSettings":{
// "connectionReuse":true, 也刪除
"path":"/pray",
// headers也刪除
}
},

All 2 comments

你的 server 有这一段
streamSettings": {
"network":"ws",
"security":"tls",
"tlsSettings": {
"allowInsecure": true,
"serverName":"vm.mysite.com"
},

你的 nginx 有这一段
location /pray {
proxy_redirect off;
proxy_pass http://127.0.0.1:14637

这对配接有点问题,nginx用http问 127. 0.0.1:14637, 但v2ray 就用tls代接。

试试server只保留以下指令
"streamSettings": {
"network":"ws",
//刪除 tls部分
"wsSettings":{
// "connectionReuse":true, 也刪除
"path":"/pray",
// headers也刪除
}
},

你的 server 有这一段
streamSettings": {
"network":"ws",
"security":"tls",
"tlsSettings": {
"allowInsecure": true,
"serverName":"vm.mysite.com"
},

你的 nginx 有这一段
location /pray {
proxy_redirect off;
proxy_pass http://127.0.0.1:14637

这对配接有点问题,nginx用http问 127. 0.0.1:14637, 但v2ray 就用tls代接。

试试server只保留以下指令
"streamSettings": {
"network":"ws",
//刪除 tls部分
"wsSettings":{
// "connectionReuse":true, 也刪除
"path":"/pray",
// headers也刪除
}
},

非常感谢,成功了。

Was this page helpful?
0 / 5 - 0 ratings