How to Configure NGINX as a reverse WebSocket proxy to V2ray through UDS
-
What version of V2Ray are you using (If you deploy different version on server and client, please explicitly point out)? V3.31
-
What's your scenario of using V2Ray? E.g., Watching YouTube videos in Chrome via Socks/VMess proxy. Anything on proxy
-
What did you see? (Please describe in detail, such as timeout, fake TLS certificate etc) Unable to Connect
-
What's your expectation?
-
Please attach your configuration file (Mask IP addresses before submit this issue).
Server configuration:
// Please attach your server configuration here.
{
"network": "ds",
"dsSettings": {
"path": "/tmp/v2ray.sock"
}
}
Client configuration:
// Please attach your client configuration here.
{
"network": "ws",
"security": "tls",
"wsSettings": {
"path": "/"
}
}
-
Please attach error logs, especially the bottom lines if the file is large. Error log file is usually at
/var/log/v2ray/error.logon Linux.Server error log:
// Please attach your server error log here.
At first nothing is abnormal here, meanwhile I figuring out that the file permission of socket is 775. On condition that Nginx and V2ray are running on different user, so I changed the file permission to 777, then I received a lot error messages **"invalid user".**
Client error log:
// Please attach your client error log here.
Everytime I got "Failed to find an available destination" error, It's a problem while trying to find a v2ray server.
- Please attach access log. Access log is usually at '/var/log/v2ray/access.log' on Linux.
// Please attach your server access log here.
A lot things like "Permission denied"
Please review your issue before submitting.
-
Other configurations (such as Nginx) and logs.
location / { proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; proxy_pass http://unix:/tmp/v2ray.sock; }
-
If V2Ray doesn't run, please attach output from
--test.
The command is usually /usr/bin/v2ray/v2ray --test --config /etc/v2ray/config.json, but may vary according to your scenario.
- If V2Ray service doesn't run, please attach journal log.
Usual command is journalctl -u v2ray.
Though we should use the same transfer method on Server and Client(like both use WebSocket), I wanna Configure NGINX as a reverse WebSocket proxy to V2ray through UDS not TCP loopback, SO how to solve this problem?
What is the detailed error message after you change file permission? "Invalid user" from VMess?
Nginx error.log: [error] 27004#27004: *175 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: xxx.xxx.xxx , request: "GET /abcdefg/ HTTP/1.1", upstream: "http://unix:/var/run/v2ray/v2ray.sock:/abcdefg/", host: "xxx.xxx.xxx"
V2ray access.log: @ rejected Proxy|VMess|Encoding: invalid user
Nginx and v2ray are run at the same User “www-data”.
V2 access.log @ rejected Proxy|VMess|Encoding: invalid user
V2 error.log [Info] [4231965309] App|Proxyman|Inbound: connection ends > Proxy|VMess|Inbound: invalid request from @ > Proxy|VMess|Encoding: invalid user
The current socket file permission is 777.
Machine translation is attached below
问题在于nginx转发的是http数据(你的情况是ws数据),
我猜v2ray的ds用的是其他数据格式,
所以他读不懂nginx转发过来的数据,
于是出现上面的错误提示.
如果某天ds变成in(out)bound协议也许能解决这个问题.
目前可以用ssh代替nginx转发domain socket,像这样:
ssh -L /tmp/client.sock:/tmp/v2ray.sock -p 443 [email protected]
抱歉,这并没有真正解决你的问题
The problem is that nginx forwards http data (your case is ws data),
I GUESS v2ray's ds uses other data formats.
So he don’t understand the data that nginx forwards.
Then the above error message appears.
If ds becomes an in(out)bound protocol someday, it may solve this problem.
Currently you can use ssh instead of nginx to forward domain sockets like this:
ssh -L /tmp/client.sock:/tmp/v2ray.sock -p 443 [email protected]
Sorry, this didn't really solve your problem.
Tunneling through Nginx is not an expected scenario for Unix domain sockets, at least for now. It requires some additional changes to support that.