主机论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 4074|回复: 21

V2Ray 一直无法连接,有报错信息

[复制链接]

13

主题

860

回帖

2667

积分

金牌会员

Rank: 6Rank: 6

积分
2667
发表于 2022-7-20 10:48:15 | 显示全部楼层 |阅读模式
这个问题已经困扰我3天了,一直没有解决,请教一下各位18cm的mjj该如何解决这个问题。

我使用了 docker compose 部署了 V2Ray 的 vmess + tls + ws 方案,容器可以正常运行,却一直无法连接。

下面的是我的配置文件,麻烦帮忙看一下,配置是否出错了。

docker-compose.yml (docker compose 配置文件)

  1. version: '3'

  2. services:

  3. nginx:
  4. # 镜像
  5. image: nginx
  6. # 容器名
  7. container_name: nginx
  8. # 端口
  9. ports:
  10. # 80 端口
  11. - "80:80"
  12. # 443 端口
  13. - "443:443"
  14. # 数据卷
  15. volumes:
  16. # Nginx 配置文件夹
  17. - "./nginx/config:/etc/nginx/conf.d"
  18. # Nginx 站点的根目录
  19. - "./nginx/html:/html"
  20. # Nginx 日志文件夹
  21. - "./nginx/log:/log"
  22. # SSL 证书文件夹
  23. - "./nginx/ssl:/ssl"
  24. # 在容器退出时,总是重启容器
  25. restart: always

  26. v2ray:
  27. # 镜像
  28. image: v2ray/official
  29. # 容器名
  30. container_name: v2ray
  31. # 数据卷
  32. volumes:
  33. # V2Ray 配置文件
  34. - ./v2ray/config/config.json:/etc/v2ray/config.json
  35. # V2Ray 访问日志文件
  36. - ./v2ray/log/access.log:/var/log/v2ray/access.log
  37. # V2Ray 错误日志文件
  38. - ./v2ray/log/error.log:/var/log/v2ray/error.log
  39. # 在容器退出时,总是重启容器
  40. restart: always
复制代码


v2ray.conf (Nginx 配置文件)

  1. server {

  2. listen 443 ssl;
  3. listen [::]:443 ssl;

  4. ssl_certificate /path/to/cert/file;
  5. ssl_certificate_key /path/to/cert/file;
  6. ssl_session_timeout 1d;
  7. ssl_session_cache shared:MozSSL:10m;
  8. ssl_session_tickets off;

  9. ssl_protocols TLSv1.2 TLSv1.3;
  10. ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
  11. ssl_prefer_server_ciphers off;

  12. server_name domain.com;

  13. # 与 V2Ray 配置中的 path 保持一致
  14. location /v2ray {

  15. # WebSocket协商失败时返回404
  16. if ($http_upgrade != "websocket") {
  17. return 404;
  18. }

  19. proxy_redirect off;

  20. # 假设WebSocket监听在环回地址的10000端口上
  21. proxy_pass http://v2ray:1024;
  22. proxy_http_version 1.1;
  23. proxy_set_header Upgrade $http_upgrade;
  24. proxy_set_header Connection "upgrade";
  25. proxy_set_header Host $host;

  26. # Show real IP in v2ray access.log
  27. proxy_set_header X-Real-IP $remote_addr;
  28. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  29. }

  30. # 访问日志
  31. access_log/log/domain.com.log;

  32. }
复制代码


V2Ray 服务器配置文件


  1. {
  2. "log": {
  3. "loglevel": "warning",
  4. "access": "/var/log/v2ray/access.log",
  5. "error": "/var/log/v2ray/error.log"
  6. },
  7. "inbounds": [
  8. {
  9. "port": 1024,
  10. "listen":"127.0.0.1",
  11. "protocol": "vmess",
  12. "settings": {
  13. "clients": [
  14. {
  15. "id": "uuid",
  16. "alterId": 0
  17. }
  18. ]
  19. },
  20. "streamSettings": {
  21. "network": "ws",
  22. "wsSettings": {
  23. "path": "/v2ray"
  24. }
  25. }
  26. }
  27. ],
  28. "outbounds": [
  29. {
  30. "protocol": "freedom",
  31. "settings": {}
  32. }
  33. ]
  34. }
复制代码


V2Ray 客户端配置文件



  1. // 通过 V2RayN 导出为客户端配置文件
  2. {
  3. "policy": {
  4. "system": {
  5. "statsOutboundUplink": true,
  6. "statsOutboundDownlink": true
  7. }
  8. },
  9. "log": {
  10. "access": "",
  11. "error": "",
  12. "loglevel": "warning"
  13. },
  14. "inbounds": [
  15. {
  16. "tag": "socks",
  17. "port": 10808,
  18. "listen": "127.0.0.1",
  19. "protocol": "socks",
  20. "sniffing": {
  21. "enabled": true,
  22. "destOverride": [
  23. "http",
  24. "tls"
  25. ]
  26. },
  27. "settings": {
  28. "auth": "noauth",
  29. "udp": true,
  30. "allowTransparent": false
  31. }
  32. },
  33. {
  34. "tag": "http",
  35. "port": 10809,
  36. "listen": "127.0.0.1",
  37. "protocol": "http",
  38. "sniffing": {
  39. "enabled": true,
  40. "destOverride": [
  41. "http",
  42. "tls"
  43. ]
  44. },
  45. "settings": {
  46. "udp": false,
  47. "allowTransparent": false
  48. }
  49. },
  50. {
  51. "tag": "api",
  52. "port": 59712,
  53. "listen": "127.0.0.1",
  54. "protocol": "dokodemo-door",
  55. "settings": {
  56. "udp": false,
  57. "address": "127.0.0.1",
  58. "allowTransparent": false
  59. }
  60. }
  61. ],
  62. "outbounds": [
  63. {
  64. "tag": "proxy",
  65. "protocol": "vmess",
  66. "settings": {
  67. "vnext": [
  68. {
  69. "address": "domain.com",
  70. "port": 443,
  71. "users": [
  72. {
  73. "id": "uuid",
  74. "alterId": 0,
  75. "email": "t@t.tt",
  76. "security": "auto"
  77. }
  78. ]
  79. }
  80. ]
  81. },
  82. "streamSettings": {
  83. "network": "ws",
  84. "security": "tls",
  85. "tlsSettings": {
  86. "allowInsecure": true,
  87. "serverName": "domain.com"
  88. },
  89. "wsSettings": {
  90. "path": "/v2ray",
  91. "headers": {
  92. "Host": "domain.com"
  93. }
  94. }
  95. },
  96. "mux": {
  97. "enabled": false,
  98. "concurrency": -1
  99. }
  100. },
  101. {
  102. "tag": "direct",
  103. "protocol": "freedom",
  104. "settings": {}
  105. },
  106. {
  107. "tag": "block",
  108. "protocol": "blackhole",
  109. "settings": {
  110. "response": {
  111. "type": "http"
  112. }
  113. }
  114. }
  115. ],
  116. "stats": {},
  117. "api": {
  118. "tag": "api",
  119. "services": [
  120. "StatsService"
  121. ]
  122. },
  123. "routing": {
  124. "domainStrategy": "IPIfNonMatch",
  125. "domainMatcher": "linear",
  126. "rules": [
  127. {
  128. "type": "field",
  129. "inboundTag": [
  130. "api"
  131. ],
  132. "outboundTag": "api",
  133. "enabled": true
  134. },
  135. {
  136. "type": "field",
  137. "port": "0-65535",
  138. "outboundTag": "proxy",
  139. "enabled": true
  140. }
  141. ]
  142. }
  143. }
复制代码


domain.com.log (Nginx 日志文件)

  1. 162.142.125.210 - - [19/Jul/2022:10:00:00 +0000] "GET / HTTP/1.1" 404 153 "-" "-"
  2. 162.142.125.210 - - [19/Jul/2022:10:00:00 +0000] "GET / HTTP/1.1" 404 153 "-" "Mozilla/5.0 (compatible; CensysInspect/1.1; +https://about.censys.io/)"
  3. 172.70.210.164 - - [19/Jul/2022:10:00:06 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  4. 172.70.210.164 - - [19/Jul/2022:10:00:06 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  5. 172.69.33.240 - - [19/Jul/2022:10:00:06 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
复制代码


V2Ray 服务端日志文件



  1. 2022/07/19 09:57:02 [Warning] v2ray.com/core: V2Ray 4.22.1 started
复制代码


V2Ray 客户端日志文件

  1. // 在这里附上客户端日志

  2. 配置成功
  3. [Vmess] V2Ray(v2ray***com:443)
  4. 启动服务(2022/7/19 18:35:25)...
  5. V2Ray 4.42.2 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.17.1 windows/386)
  6. A unified platform for anti-**ship.
  7. 2022/07/19 18:35:25 [Info] main/jsonem: Reading config: D:\Software\v2rayN-Core\config.json
  8. 2022/07/19 18:35:25 [Warning] V2Ray 4.42.2 started
  9. 2022/07/19 18:35:25 127.0.0.1:61280 accepted //mtalk.google.com:5228 [proxy]
  10. 2022/07/19 18:35:25 127.0.0.1:61281 accepted //bl3301.storage.live.com:443 [proxy]
  11. 2022/07/19 18:35:26 127.0.0.1:61286 accepted tcp:127.0.0.1:0 [api]
  12. 2022/07/19 18:35:30 127.0.0.1:61292 accepted //www.google.com:443 [proxy]
  13. 2022/07/19 18:35:30 127.0.0.1:61294 accepted //alive.github.com:443 [proxy]
  14. 2022/07/19 18:35:35 127.0.0.1:61308 accepted //alive.github.com:443 [proxy]
  15. 2022/07/19 18:35:36 [Warning] [2092548641] app/proxyman/outbound: failed to process outbound traffic > proxy/vmess/outbound: failed to find an available destination > common/retry: [transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://domain.com/v2ray): 502 Bad Gateway > websocket: bad handshake] > common/retry: all retry attempts failed
  16. 2022/07/19 18:35:36 127.0.0.1:61311 accepted //mtalk.google.com:5228 [proxy]
  17. 2022/07/19 18:35:39 [Warning] [2069622245] app/proxyman/outbound: failed to process outbound traffic > proxy/vmess/outbound: failed to find an available destination > common/retry: [transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://domain.com/v2ray): 502 Bad Gateway > websocket: bad handshake] > common/retry: all retry attempts failed
  18. 2022/07/19 18:35:39 127.0.0.1:61321 accepted //alive.github.com:443 [proxy]
  19. 2022/07/19 18:35:40 [Warning] [2041129081] app/proxyman/outbound: failed to process outbound traffic > proxy/vmess/outbound: failed to find an available destination > common/retry: [transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://domain.com/v2ray): 502 Bad Gateway > websocket: bad handshake] > common/retry: all retry attempts failed
  20. 2022/07/19 18:35:40 127.0.0.1:61326 accepted //www.google.com:443 [proxy]
复制代码
回复

使用道具 举报

13

主题

860

回帖

2667

积分

金牌会员

Rank: 6Rank: 6

积分
2667
 楼主| 发表于 2022-7-20 12:47:42 | 显示全部楼层
本帖最后由 Jianrry 于 2022-7-20 17:31 编辑
huaxing0211 发表于 2022-7-20 11:37
"listen":"127.0.0.1",
docker里用0.0.0.0,或是删除,默认


非常感谢大佬的回复,问题就是出在这里。

刚才按照大佬的回复,修改完配置文件之后。

v2ray 多出了访问日志 access.log,之前的 access.log 的内容一直为空,现在 nginx 已经转发到 v2ray 了。

又出现了新的问题,还没有解决,大佬能再帮忙看一下吗?

v2ray 访问日志 access.log

  1. 2022/07/20 04:34:18 [2409:8a55:4e97:3e20:5cb2:69ba:f042:cf3f]:58494 rejectedv2ray.com/core/proxy/vmess/encoding: invalid user
  2. 2022/07/20 04:34:18 [2409:8a55:4e97:3e20:5cb2:69ba:f042:cf3f]:58492 rejectedv2ray.com/core/proxy/vmess/encoding: failed to read request header > websocket: close 1000 (normal)
复制代码


网上的回复说与时间有关,需要校对时间。

我已经尝试过了修改服务器的时区为上海时区,通过 ntpdate -u time.windows.com 校对时间,误差不超过1s ,本地电脑的时间也校对过了。

重新检查了一下 v2ray 的配置文件,但是还没有发现问题。

麻烦路过的各位大佬,多多指点一下。

回复

使用道具 举报

8

主题

234

回帖

814

积分

高级会员

Rank: 4

积分
814
发表于 2022-7-20 11:37:00 | 显示全部楼层
本帖最后由 摩卡 于 2022-7-20 10:56 编辑

看下nginx的日志 有没有转发到v2容器
另外我看v2容器没有配置端口号 你配置下端口映射规则试试?
回复

使用道具 举报

297

主题

4199

回帖

1万

积分

论坛元老

Rank: 8Rank: 8

积分
10735
发表于 2022-7-20 10:52:39 | 显示全部楼层
用aapanrl面板吧。方便管理https://daima.eu.org/post/bt-v2ray/
回复

使用道具 举报

7

主题

236

回帖

779

积分

高级会员

Rank: 4

积分
779
发表于 2022-7-20 10:52:32 | 显示全部楼层
别的不说,先校时,保证二者相差不超过90s
回复

使用道具 举报

7

主题

115

回帖

451

积分

中级会员

Rank: 3Rank: 3

积分
451
发表于 2022-7-20 11:01:52 | 显示全部楼层
domain.com 是本来就是这样写的,还是你打码了的
回复

使用道具 举报

13

主题

860

回帖

2667

积分

金牌会员

Rank: 6Rank: 6

积分
2667
 楼主| 发表于 2022-7-20 11:04:56 | 显示全部楼层
本帖最后由 Jianrry 于 2022-7-20 11:11 编辑
摩卡 发表于 2022-7-20 10:52
看下nginx的日志 有没有转发到v2容器
另外我看v2容器没有配置端口号 你配置下端口映射规则试试? ...


我不知道如何判断是否转发,麻烦大佬帮我看一下,下面是 nginx 的日志文件。

  1. [code]162.142.125.210 - - [19/Jul/2022:10:00:00 +0000] "GET / HTTP/1.1" 404 153 "-" "-"
  2. 162.142.125.210 - - [19/Jul/2022:10:00:00 +0000] "GET / HTTP/1.1" 404 153 "-" "Mozilla/5.0 (compatible; CensysInspect/1.1; +https://about.censys.io/)"
  3. 172.70.210.164 - - [19/Jul/2022:10:00:06 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  4. 172.70.210.164 - - [19/Jul/2022:10:00:06 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  5. 172.69.33.240 - - [19/Jul/2022:10:00:06 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  6. 172.69.33.240 - - [19/Jul/2022:10:00:06 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  7. 172.68.254.38 - - [19/Jul/2022:10:00:06 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  8. 172.69.33.240 - - [19/Jul/2022:10:00:06 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  9. 172.68.254.38 - - [19/Jul/2022:10:00:07 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  10. 172.70.214.84 - - [19/Jul/2022:10:00:07 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  11. 172.69.33.240 - - [19/Jul/2022:10:00:07 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
  12. 172.69.33.240 - - [19/Jul/2022:10:00:07 +0000] "GET /v2ray HTTP/1.1" 502 157 "-" "Go-http-client/1.1"
复制代码

另外我看v2容器没有配置端口号 你配置下端口映射规则试试?


v2 容器用的是 1024 端口,通过 nginx 反向代理转发到 443 端口,443 端口映射为本机的 443 端口,这个已经配置了。

V2Ray 服务器配置文件


  1. ...
  2. "inbounds": [
  3. {
  4. "port": 1024,
  5. ...
复制代码


v2ray.conf (Nginx 配置文件)

  1. ...
  2. # 假设WebSocket监听在环回地址的10000端口上
  3. proxy_pass http://v2ray:1024;
  4. ...
复制代码


docker-compose.yml (docker compose 配置文件)

  1. ...
  2. # 端口
  3. ports:
  4. # 80 端口
  5. - "80:80"
  6. # 443 端口
  7. - "443:443"
  8. ...
复制代码
回复

使用道具 举报

13

主题

860

回帖

2667

积分

金牌会员

Rank: 6Rank: 6

积分
2667
 楼主| 发表于 2022-7-20 11:07:57 | 显示全部楼层
toot 发表于 2022-7-20 10:52
用aapanrl面板吧。方便管理https://daima.eu.org/post/bt-v2ray/

不习惯用面板,习惯用 docker 一把梭了。。。
回复

使用道具 举报

13

主题

860

回帖

2667

积分

金牌会员

Rank: 6Rank: 6

积分
2667
 楼主| 发表于 2022-7-20 10:52:00 | 显示全部楼层
汤家凤 发表于 2022-7-20 11:01
别的不说,先校时,保证二者相差不超过90s

已经修改时区 和 校时 了,服务器时间和本机时间相差不到1min.
回复

使用道具 举报

25

主题

211

回帖

827

积分

高级会员

Rank: 4

积分
827
发表于 2022-7-20 11:09:07 | 显示全部楼层
nginx 报错502 说明连接不到后端

再看你的docker compose文件,两个容器之间没有定义关联网络,两个容器网络是不通的

要么用link关联 要么定义一个网络两个容器加入

参考 https://docs.docker.com/compose/networking/
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|主机论坛

GMT+8, 2025-8-20 03:28 , Processed in 0.041827 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表