v2ray / discussion

For general discussion over Project V development and usage.
299 stars 34 forks source link

V2Ray直接访问IP正常,套上CDN就访问失败 #294

Closed flowingcloud516 closed 3 years ago

flowingcloud516 commented 5 years ago

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

1) 你正在使用哪个版本的 V2Ray?(如果服务器和客户端使用了不同版本,请注明) server 4.19.1 client 4.19.1

2) 你的使用场景是什么?比如使用 Chrome 通过 Socks/VMess 代理观看 YouTube 视频。 登录 facebook

3) 你看到的不正常的现象是什么?(请描述具体现象,比如访问超时,TLS 证书错误等) 直连IP可以正常访问,开启CDN后一直400,然后 trial fail

4) 你期待看到的正确表现是怎样的?

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

服务器端配置:

    // 在这里附上服务器端配置文件
{
  "log" : {
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log",
    "loglevel": "warning"
  },
  "inbounds": [
      {
        "port": 443,
        "protocol": "vmess",
        "settings": {
          "clients": [
            {
              "id": "myid",
              "level": 1,
              "alterId": 64
            }
          ]
        },
        "streamSettings": {
            "tlsSettings": {},
            "security": "none",
            "wsSettings":{
                "path":"/",
                "connectionReuse": true,
                "headers": {}
            },
            "httpSettings": {},
            "network": "ws",
            "quicSettings": {},
            "tcpSettings": {},
            "kcpSettings": {}
         }
      }
  ],
  "outbounds": [{
    "protocol": "freedom",
    "settings": {}
  },{
    "protocol": "blackhole",
    "settings": {},
    "tag": "blocked"
  }],
  "routing": {
    "rules": [
      {
        "type": "field",
        "ip": [
          "0.0.0.0/8",
          "10.0.0.0/8",
          "100.64.0.0/10",
          "169.254.0.0/16",
          "172.16.0.0/12",
          "192.0.0.0/24",
          "192.0.2.0/24",
          "192.168.0.0/16",
          "198.18.0.0/15",
          "198.51.100.0/24",
          "203.0.113.0/24",
          "::1/128",
          "fc00::/7",
          "fe80::/10"
        ],
        "outboundTag": "blocked"
      }
    ]
  }
}

客户端配置: 客户端用的 V2RayU,配置文件似乎是自动生成的

    // 在这里附上客户端配置
{
  "log": {
    "error": "",
    "loglevel": "info",
    "access": ""
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "protocol": "socks",
      "settings": {
        "ip": "",
        "userLevel": 0,
        "timeout": 360,
        "udp": false,
        "auth": "noauth"
      },
      "port": "1080"
    },
    {
      "listen": "127.0.0.1",
      "protocol": "http",
      "settings": {
        "timeout": 360
      },
      "port": "11081"
    }
  ],
  "outbounds": [
    {
      "mux": {
        "enabled": false,
        "concurrency": 8
      },
      "protocol": "vmess",
      "streamSettings": {
        "wsSettings": {
          "path": "/",
          "headers": {
            "host": ""
          }
        },
        "tlsSettings": {
          "allowInsecure": true
        },
        "security": "none",
        "network": "ws"
      },
      "tag": "agentout",
      "settings": {
        "vnext": [
          {
            "address": "sample.com",
            "users": [
              {
                "id": "myid",
                "alterId": 64,
                "level": 1,
                "security": "auto"
              }
            ],
            "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/07/11 22:31:44 [Info] [3222177647] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:44 [Info] [2564962590] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [1524986387] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [3151303011] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [3649197847] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [1114405525] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [46966096] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [1312118754] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [4112035259] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [3583029335] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [3222177647] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] [2564962590] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:45 [Info] v2ray.com/core/features: You are using a deprecated feature: Socks timeout. Please update your config file with latest configuration format, or update your client software.
2019/07/11 22:31:45 tcp:127.0.0.1:57640 accepted tcp:www.facebook.com:443 
2019/07/11 22:31:45 [Info] [3899918288] v2ray.com/core/proxy/socks: TCP Connect request to tcp:www.facebook.com:443
2019/07/11 22:31:45 [Info] v2ray.com/core/features: You are using a deprecated feature: Socks timeout. Please update your config file with latest configuration format, or update your client software.
2019/07/11 22:31:45 [Info] v2ray.com/core/features: You are using a deprecated feature: Socks timeout. Please update your config file with latest configuration format, or update your client software.
2019/07/11 22:31:45 [Info] [3899918288] v2ray.com/core/app/dispatcher: default route for tcp:www.facebook.com:443
2019/07/11 22:31:45 [Info] [3899918288] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:46 [Info] [1524986387] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:46 [Info] [3899918288] v2ray.com/core/transport/internet/websocket: creating connection to tcp:sample.com:443
2019/07/11 22:31:46 [Warning] [3649197847] 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 (ws://sample.com:443/): 400 Bad Request > websocket: bad handshake] > v2ray.com/core/common/retry: all retry attempts failed
2019/07/11 22:31:46 [Warning] [1114405525] 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 (ws://sample.com:443/): 400 Bad Request > websocket: bad handshake] > v2ray.com/core/common/retry: all retry attempts failed
2019/07/11 22:31:46 [Info] [3649197847] 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)和相关日志。 没有配置 nginx

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

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

10) 如果 V2Ray 服务运行不正常,请附上 journal 日志。

通常的命令为 journalctl -u v2ray

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

kslr commented 5 years ago

ws://sample.com:443/ 配置路径错误了,更换成自己的

flowingcloud516 commented 5 years ago

ws://sample.com:443/ 配置路径错误了,更换成自己的

这个路径在哪里改? 另外,如果是路径错误的话,讲道理 sample.com 换成 VPS 的IP也访问不了吧?

kingwilliam commented 5 years ago
  1. 您是否真的有自己domain如sample.com?

  2. 您已修改dns a record到CDN地址?

  3. 修改完dns後等了多久?因要等ttl.

  4. 如已确定上面3点,试试修改dns a record 指到您v2ray server ip.

flowingcloud516 commented 5 years ago
  1. 您是否真的有自己domain如sample.com?
  2. 您已修改dns a record到CDN地址?
  3. 修改完dns後等了多久?因要等ttl.
  4. 如已确定上面3点,试试修改dns a record 指到您v2ray server ip.

可能引起了你们的误会? 我是用 sample.com 替换了自己的域名 DNS record 已生效。从 dig 命令可以看出来 DNS不经过CDN,直接到VPS IP 是可以正常使用的。 CDN用的 cloudflare,状态已经 active

kingwilliam commented 5 years ago

有几点想先了解 1。再看您server config是用端口443,但就没tls和没电子证书。只是用一般websocket 对吗?(还是只没放上来) 2。再看您的client config, 是有tls设定。 "tlsSettings": { "allowInsecure": true }, 3。 您是否已在cdn放入电子证书?

k79e commented 5 years ago

急速测试 走cdn 直接访问ws那个地址 报400就是成功接入. 服务端开了tls 不知道是否cf能接过去 cf他们会提供给你一个证书然后让cf节点到服务器加密访问. 其他证书不知道cf是否能验证通过. 总之直接访问地址就行了 没400就没法用. 服务端ws 的tls关了要是出现400那就正常了. 好了我走了.

flowingcloud516 commented 5 years ago

急速测试 走cdn 直接访问ws那个地址 报400就是成功接入. 服务端开了tls 不知道是否cf能接过去 cf他们会提供给你一个证书然后让cf节点到服务器加密访问. 其他证书不知道cf是否能验证通过. 总之直接访问地址就行了 没400就没法用. 服务端ws 的tls关了要是出现400那就正常了. 好了我走了.

直接访问IP不报400。不论是以客户端的配置IP的方式,还是设置CDN直连,都可以正常使用。

flowingcloud516 commented 5 years ago

有几点想先了解 1。再看您server config是用端口443,但就没tls和没电子证书。只是用一般websocket 对吗?(还是只没放上来) 2。再看您的client config, 是有tls设定。 "tlsSettings": { "allowInsecure": true }, 3。 您是否已在cdn放入电子证书?

1.只是一般的用websocket,没有加tls 2.tls设定是要关掉的意思?我理解 allowInsecure为true,应该是允许非安全访问的意思吧? 3.没设置。还没搞到tls这块来

flowingcloud516 commented 5 years ago

急速测试 走cdn 直接访问ws那个地址 报400就是成功接入. 服务端开了tls 不知道是否cf能接过去 cf他们会提供给你一个证书然后让cf节点到服务器加密访问. 其他证书不知道cf是否能验证通过. 总之直接访问地址就行了 没400就没法用. 服务端ws 的tls关了要是出现400那就正常了. 好了我走了.

我想尝试一下服务端强制关闭tls,不知道应该怎么填参数?

kingwilliam commented 5 years ago

参考: https://www.v2ray.com/chapter_02/05_transport.html

allowInsecure: true | false 是否允许不安全连接(用于客户端)。当值为true时,V2Ray 不会检查远端主机所提供的 TLS 证书的有效性。

解读: 说白点, 就是“是否用自签电子证书” 如您用的是“自签电子证书” allowInsecure: 就要true 如电子证书是由合法第三方发出,如CDN或let's encrypt, allowInsecure: 就可以false

flowingcloud516 commented 5 years ago

参考: https://www.v2ray.com/chapter_02/05_transport.html

allowInsecure: true | false 是否允许不安全连接(用于客户端)。当值为true时,V2Ray 不会检查远端主机所提供的 TLS 证书的有效性。

解读: 说白点, 就是“是否用自签电子证书” 如您用的是“自签电子证书” allowInsecure: 就要true 如电子证书是由合法第三方发出,如CDN或let's encrypt, allowInsecure: 就可以false

客户端设置成 "allowInsecure": false,依旧无效。 还有什么排查思路吗。。

kingwilliam commented 5 years ago

您现在的问题 应由CDN开始,

  1. 首先看看您的CDN“有没冇用电子证书”
    • 如有tls, 各户端就要有 "streamSettings": { "network": "ws", "security": "tls", "tlsSettings": { "allowInsecure": true }, "wsSettings": { "path": "/" } }
  1. 再看vps, 因您的domain已指向cdn, 这时在cdn出站连接vps就不能再用同一个FQDN, 例如: 国内手机去CDN client---(wss://www.simple.com)--->CDN 出站就要用另一个 FQDN 如 CDN---(wss://ww1.simple.com)--->vps (当然如您有两张电子证书) 出站也可以用IP但不用证书 如 CDN---(ws://x.x.x.x)--->vps (x.x.x.x=ip address)
flowingcloud516 commented 5 years ago

您现在的问题 应由CDN开始,

  1. 首先看看您的CDN“有没冇用电子证书”

{ 补充中 }

CDN用的 cloudflare,但是不是很确定有没有关掉。 Crypto 里面有一项是 “Disable Universal SSL”,刚刚disable掉了,应该是关了吧?

kingwilliam commented 5 years ago

如已关掉ssl, 就要留意cdn端口是否还是443

flowingcloud516 commented 5 years ago

如已关掉ssl, 就要留意cdn端口是否还是443

平台上看不到CDN的端口。实在不知道这个怎么看。。。 刚刚观察了一下日志,如果直连IP,access.log 会打印访问日志,但是走CDN的话,访问日志也没有。会不会是CDN设置的问题?但是有什么办法验证这个猜想吗?

mo-han commented 5 years ago

ws服务端配置好之后,直接访问ws的完整地址(ip或域名+path),应该是返回200代码,以及一个源码为“Bad Request”的网页。而不是返回400代码,因为400代码本身代表真正的“Bad Request”。

不走cdn能正常连接,说明服务器配置没毛病。

然而从cdn连接却得到一个400代码,讲道理,这是cdn的锅。缓存策略有问题?缓存没有及时更新?服务商压根不支持ws(据我所知支持ws的cdn服务商真的很少)? 喂,你用的cdn莫非不是cf?

kingwilliam commented 5 years ago

我相信你是电子证书问题

如果你只是ws 不设 tls client server 两边都要 停tls. cf crypto ssl 就要off Client outgoing server incoming 都要设定 80

但 如果你要 ws+tls client server 两边都要enable tls. cf crypto ssl 就要Full(strict) Client outgoing server incoming 都要设定 443 Server那边还要设电子证书

在 CF Crypto设定电子证书

Others :

上面所提及的 是基於 要经过 CDN 所以一定一定要 ws port 80, ws+tls port 443. 到你成功连接後再一步一步往上推。 以下是 cf crypto 参考

https://support.cloudflare.com/hc/en-us/articles/200170416-End-to-end-HTTPS-with-Cloudflare-Part-3-SSL-options

ghost commented 4 years ago

https://www.johnrosen1.com/v2ray-cdn/ 你可以参考参考,tls推荐开启

ghost commented 4 years ago

我也遇到了相同的问题,一套cdn,v2ray就失效,有没有证书都一样,和证书无关,不知道楼主解决了没有呢?

upupming commented 4 years ago

@flowingcloud516 @yanlianglai 注意如果是 CloudFlare 的话,WebSocket 连接是默认关闭的。需要手动打开 Network 下面的 WebSocket 开关,如下图所示:

image image

还可以在自己的 VPS 上通过 wscat 命令验证 CloudFlare 配置的正确性:

$ sudo apt install node-ws
$ wscat -c ws://127.0.0.1:你的端口
connected (press CTRL+C to quit)

# 配置好 CloudFlare 之前
$ wscat -c wss://你的域名/你的path
error: Error: unexpected server response (400)

# 配置好 CloudFlare 之后
$ wscat -c wss://你的域名/你的path
connected (press CTRL+C to quit)
davidlauhn commented 4 years ago

我也遇到了相同的问题,一套cdn,v2ray就失效,有没有证书都一样,和证书无关,不知道楼主解决了没有呢?

一样,所以现在只能不套CDN裸奔了

benwk commented 4 years ago

我也遇到了相同的问题,一套cdn,v2ray就失效,有没有证书都一样,和证书无关,不知道楼主解决了没有呢?

如果主机端口是 443,打开 TLS 并且配置了证书

需要在 CloudFlare 上将 SSL/TLS encryption mode 改为 Full (strict),再打开 Always Use HTTPS,基本就能解决了

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days

lipeng1667 commented 3 years ago

CF上如果要使用自己的SSL证书 收费好贵,所以是不是意味着 如果要套CDN,就不能用tls了。。。

heccjj commented 3 years ago

@flowingcloud516 @yanlianglai 注意如果是 CloudFlare 的话,WebSocket 连接是默认关闭的。需要手动打开 Network 下面的 WebSocket 开关,如下图所示:

image image

还可以在自己的 VPS 上通过 wscat 命令验证 CloudFlare 配置的正确性:

$ sudo apt install node-ws
$ wscat -c ws://127.0.0.1:你的端口
connected (press CTRL+C to quit)

# 配置好 CloudFlare 之前
$ wscat -c wss://你的域名/你的path
error: Error: unexpected server response (400)

# 配置好 CloudFlare 之后
$ wscat -c wss://你的域名/你的path
connected (press CTRL+C to quit)

正解,解决了我一个长期烦恼!

Flikify commented 2 years ago

@flowingcloud516 @yanlianglai 注意如果是 CloudFlare 的话,WebSocket 连接是默认关闭的。需要手动打开 Network 下面的 WebSocket 开关,如下图所示:

图片 图片

还可以在自己的 VPS 上通过wscat命令验证 CloudFlare 配置的正确性:

$ sudo apt install node-ws
$ wscat -c ws://127.0.0.1:你的端口
connected (press CTRL+C to quit)

# 配置好 CloudFlare 之前
$ wscat -c wss://你的域名/你的path
error: Error: unexpected server response (400)

# 配置好 CloudFlare 之后
$ wscat -c wss://你的域名/你的path
connected (press CTRL+C to quit)

试了一晚上,终于解决了!

AlexYang-yz commented 1 year ago

我的情况刚好相反,我之前配置的是ws+tls, 我在v2ray的客户端配置里访问地址直接写的VPS的IP,访问都很快。但是最近突然不行了,v2ray无法连接了,然后我在访问的地址里修改为伪装的网页URL,可以访问,但是访问非常慢。我ping伪装的网站URL地址并不是我的VPS的IP(我猜是fc的CDN的IP),延迟非常高,然后我在FC的DNS设置里把proxy去掉,修改为DNS Only,我的V2ray就无法使用了。所以我想问的话我一定要使用FC的CDN么? 但是感觉这样子非常慢,twitter的图片都无法加载,更别说视频了,之前视频都非常流畅。 这里面到底是什么原因呢?

davidlauhn commented 1 year ago

主机IP被封了

我的情况刚好相反,我之前配置的是ws+tls, 我在v2ray的客户端配置里访问地址直接写的VPS的IP,访问都很快。但是最近突然不行了,v2ray无法连接了,然后我在访问的地址里修改为伪装的网页URL,可以访问,但是访问非常慢。我ping伪装的网站URL地址并不是我的VPS的IP(我猜是fc的CDN的IP),延迟非常高,然后我在FC的DNS设置里把proxy去掉,修改为DNS Only,我的V2ray就无法使用了。所以我想问的话我一定要使用FC的CDN么? 但是感觉这样子非常慢,twitter的图片都无法加载,更别说视频了,之前视频都非常流畅。 这里面到底是什么原因呢?

你是主机IP被封了,只能换IP,或忍受FC的高延迟

creky commented 1 year ago

正确原因是 nginx里面要配置上 tls3.0 ,很多教程都只配到了2.0,而cloudflare默认是用的tls3.0 从而导致无法访问,nginx里面加上这个就行了。

zhoujingchao commented 5 months ago

@flowingcloud516 @yanlianglai 注意如果是 CloudFlare 的话,WebSocket 连接是默认关闭的。需要手动打开 Network 下面的 WebSocket 开关,如下图所示:

image image

还可以在自己的 VPS 上通过 wscat 命令验证 CloudFlare 配置的正确性:

$ sudo apt install node-ws
$ wscat -c ws://127.0.0.1:你的端口
connected (press CTRL+C to quit)

# 配置好 CloudFlare 之前
$ wscat -c wss://你的域名/你的path
error: Error: unexpected server response (400)

# 配置好 CloudFlare 之后
$ wscat -c wss://你的域名/你的path
connected (press CTRL+C to quit)

请问一下,这是什么情况,需要继续往哪里排查下?现在套上cdn还是不通,直连是ok的。(v2ray的端口实际在运行的) image