alibaba / arthas

Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas
https://arthas.aliyun.com/
Apache License 2.0
35.74k stars 7.51k forks source link

web-console通过nginx反向代理连接agent失败 #2012

Open cat-fishing opened 3 years ago

cat-fishing commented 3 years ago

环境信息

重现问题的步骤

我在自己电脑部署arthas-boot,然后部署tunnel-server,通过nginx反向代理进入server页面,输入agentid,请求nginx,nginx根据反向代理ws路径转发到7777就报这个错 image nginx的location配置有问题么,按照nginx官网websocket配置的 image

期望的结果

arthas-tunnel-server通过agentId连接到arthas-boot服务这个agent

实际运行的结果

实际运行结果,最好有详细的日志,异常栈。尽量贴文本。 后台没有接收到请求,在与nginx通信进行握手时候被返回301失败 image

把异常信息贴到这里
Moonzzz commented 2 years ago

location和proxy_pass改成这样可以解决,试出来的,不知道为啥可以。

location /ws {
    proxy_pass http://localhost:7777/ws;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Host $host;
}

如果末尾加上斜杠,浏览器和agent client不可以,但是postman可以。

hengyunabc commented 2 years ago

可以参考下这个:

    # arthas tunnel server pages
    rewrite ^/arthas-tunnel$ /arthas-tunnel/ permanent;
    location ^~/arthas-tunnel/ {
        proxy_set_header Host $host;
        rewrite ^/arthas-tunnel/(.*)$ /$1 break;
        proxy_pass  http://arthas_tunnel;
    }

    # arthas tunnel server port
    location /tunnelws {
        set $target '127.0.0.1';

        access_by_lua_block {
            -- try to find target server from API
            if ngx.var.arg_id then
                local findHostUrl = "/arthas-tunnel/api/cluster/findHost?agentId=" .. ngx.var.arg_id
                local res = ngx.location.capture(findHostUrl)
                if res.status == 200 and res.body and res.body ~= "" then
                    ngx.var.target = res.body
                end
            end
        }

        proxy_pass "http://$target:7777";
        proxy_read_timeout 300s;
        proxy_send_timeout 300s;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-Port $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';