Skip to content

agent无法通过nginx反向代理连接到面板 #1137

@dann2333

Description

@dann2333

运行环境

Debian GNU/Linux 12 amd64

Nezha 版本

1.14.1

描述问题

当在后台配置为通过nginx反向代理连接到哪吒面板的时候,agent无法连接,报错如下

nezha-agent[1227257]: NEZHA@2025-11-14 01:28:31>> Try to reconnect ...
nezha-agent[1227257]: NEZHA@2025-11-14 01:28:31>> Connection to status.***.com:443 established
nezha-agent[1227257]: NEZHA@2025-11-14 01:28:43>> reportStateDaemon exit: context error: context deadline exceeded, fn err: <nil>
nezha-agent[1227257]: NEZHA@2025-11-14 01:28:43>> Worker exit...
nezha-agent[1227257]: NEZHA@2025-11-14 01:28:43>> receiveTasks exit: rpc error: code = Canceled desc = context canceled
nezha-agent[1227257]: NEZHA@2025-11-14 01:28:53>> Try to reconnect ...
nezha-agent[1227257]: NEZHA@2025-11-14 01:28:53>> Connection to status.***.com:443 established
nezha-agent[1227257]: NEZHA@2025-11-14 01:28:58>> 上报系统信息失败: rpc error: code = DeadlineExceeded desc = context deadline exceeded while waiting for connections to become ready 
nezha-agent[1227257]: NEZHA@2025-11-14 01:29:08>> Try to reconnect ...
nezha-agent[1227257]: NEZHA@2025-11-14 01:29:08>> Connection to status.***.com:443 established

已经按文档配置反向代理,使用curl测试连接没有问题
已在主配置添加

    underscores_in_headers on;
    ignore_invalid_headers off;

反向代理配置:

#PROXY-START/

location ^~ /proto.NezhaService/ {
    grpc_pass grpc://grpcservers;
    grpc_set_header Host $host;
    #grpc_set_header nz-realip $http_CF_Connecting_IP;
    grpc_set_header nz-realip $remote_addr;
    grpc_read_timeout 600s;
    grpc_send_timeout 600s;
    grpc_socket_keepalive on;
    grpc_buffer_size 4m;
}

location ~* ^/api/v1/ws/(server|terminal|file)(.*)$ {
    proxy_pass http://127.0.0.1:8008;
    proxy_set_header Host $host;
    proxy_set_header nz-realip $http_cf_connecting_ip;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
}

location / {
    proxy_pass http://127.0.0.1:8008;
    proxy_set_header Host $host;
    #proxy_set_header nz-realip $http_cf_connecting_ip;
    proxy_set_header nz-realip $remote_addr;
    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
}

#PROXY-END/

curl可以返回文档中自查的正确信息

< grpc-message: unknown method  for service proto.NezhaService
< grpc-status: 12
* Connection #0 to host status.***.com left intact

ssl证书有效,agent配置见下方
使用原始端口可以正常连接

复现步骤

配置nginx反向代理并连接

配置信息

agent配置

client_secret: ***
debug: true
disable_auto_update: false
disable_command_execute: false
disable_force_update: false
disable_nat: false
disable_send_query: false
gpu: false
insecure_tls: false
ip_report_period: 1800
report_delay: 3
self_update_period: 0
server: status.***.com:443
skip_connection_count: false
skip_procs_count: false
temperature: false
tls: true
use_gitee_to_upgrade: false
use_ipv6_country_code: false
uuid:  ***

附加信息

验证

  • 我确认这是一个 nezha (哪吒面板) 的问题。
  • 我已经搜索了 Issues,并确认该问题之前没有被反馈过。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions