v2fly / v2ray-step-by-step

This repo is a fork of ToutyRater/v2ray-guide, we aim to provide a new step-by-step guide of v2ray
https://guide.v2fly.org
Creative Commons Attribution 4.0 International
753 stars 426 forks source link

"基于 Nginx 的简单 TLS 分流"会导致其中的WEB服务器无法接受到长Path请求 #178

Open sixg0000d opened 4 years ago

sixg0000d commented 4 years ago

与 bug 有关的页面 / related page

tls_routing_with_nginx.md

bug 描述 / description of the bug

缺陷:

使用该配置,path过长的http请求无法通过proxy_pass转发给WEB服务器。

造成缺陷的原因:

当正常的HTTP流量path过长时,local data, err = sock:peek(16)只会拿到method+空格+不完整的path,无法被任何if/elseif分支匹配到,最终在else分支匹配命中,请求将会转发给V2ray后端。

复现步骤 / how we can reproduce

在此描述复现出现的问题所需的步骤和环境。

使用教程中的配置简化和修改后的配置:

worker_processes  auto;
error_log  logs/error.log  debug;
events {
    worker_connections  1024;
}
stream {
    resolver 127.0.0.1;
    lua_add_variable $VMess;

    server {
        listen  80;

        preread_by_lua_block {
            local sock, err = ngx.req.socket()
            if sock then
               -- ngx.say("got the request socket")
            else
                ngx.say("failed to get the request socket: ", err)
            end

            local data, err = sock:peek(16)
            local datal, err = sock:peek(58)
            if string.match(data, "HTTP") then
            -- for normal http req
                ngx.var.VMess = "8080"
            else
            -- for V2Ray's tcp+TLS +web
                ngx.var.VMess = "10080"
            end
        }
        proxy_pass 127.0.0.1:$VMess;
    }
}

domain.name可以替换成 ip 地址,在服务器上使用 curl 测试则可替换成localhost,皆可复现。