Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sixg0000d opened this issue Jul 5, 2020 · 0 comments
Labels
bug Something isn't working unconfirmed Waiting investigation

Comments

@sixg0000d
Copy link

sixg0000d commented Jul 5, 2020

与 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;
    }
}
  • 使用curl请求http://domain.name/123456正常,但是请求http://domain.name/1234567则会无法得到响应

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

  • 使用浏览器访问http://domain.name/1234567无法得到响应,但是使用浏览器先访问短 path 或无 path 的 url (如http://domain.name/123456)在短时间内再跳转到http://domain.name/1234567,则可获得正常的服务器响应。
    可能是preread_by_lua_block块只在浏览器的第一个请求时执行了一次?
    但即使如此,正常使用环境也有可能面临需要直接访问长path的场景,比如 V2ray 客户端从订阅链接获取节点配置时。
@sixg0000d sixg0000d added bug Something isn't working unconfirmed Waiting investigation labels Jul 5, 2020
@sixg0000d sixg0000d changed the title [bug] "基于 Nginx 的简单 TLS 分流"中可能存在一个缺陷 "基于 Nginx 的简单 TLS 分流"中可能存在一个缺陷 Jul 5, 2020
@sixg0000d sixg0000d changed the title "基于 Nginx 的简单 TLS 分流"中可能存在一个缺陷 "基于 Nginx 的简单 TLS 分流"会导致其中的WEB服务器无法接受到长Path请求 Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Waiting investigation
Projects
None yet
Development

No branches or pull requests

1 participant