首页 > 解决方案 > Wildfly 16 在 NGINX 后面带有 http-remoting:JBREM000202

问题描述

我试图将 Wildfly 16 作为反向代理放在 NGINX 后面。我想使用 http-remoting 为 EJB 提供服务。

这是我的 NGINX 配置:

server {                                                                                                                             
  listen          81;                                                                                                                
  server_name     10.0.2.15;                                                                                                         
                                                                                                                                     
  location / {                                                                                                                       
                                                                                                                                     
                                                                                                                                     
    set $should_proxy "";                                                                                                            
    set $upgrade_header "";

    if ($http_sec_jbossremoting_key) {
      set $should_proxy "Y";
    }

    if ($should_proxy = Y) {
      proxy_pass http://127.0.0.1:8080;
      set $upgrade_header "upgrade";
    }

    proxy_set_header Sec-JbossRemoting-Key $http_sec_jbossremoting_key;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Host $http_host;
    proxy_set_header Connection $upgrade_header;
    
  }
}

但是,在我得到的 EJB 客户端上

IOException: JBREM000202: Abrupt close on Remoting connection

我尝试获取 NGINX 生成的标头,并使用 tcpdump 和以下输出:

00:16:08.083162 IP (tos 0x0, ttl 64, id 34533, offset 0, flags [DF], proto TCP (6), length 185)
    localhost.34890 > localhost.http-alt: Flags [P.], cksum 0xfead (incorrect -> 0x81b5), seq 1:134, ack 1, win 512, options [nop,nop,TS val 1104278851 ecr 1104278851], length 133: HTTP, length: 133
        GET / HTTP/1.0
        Sec-JbossRemoting-Key: iy2PuEO5anDKgm4w2+o0Tw==
        Upgrade: jboss-remoting
        Host: 10.0.2.15:81
        Connection: upgrade

00:16:08.083165 IP (tos 0x0, ttl 64, id 42808, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.http-alt > localhost.34890: Flags [.], cksum 0xfe28 (incorrect -> 0x753d), ack 134, win 511, options [nop,nop,TS val 1104278851 ecr 1104278851], length 0
00:16:08.083690 IP (tos 0x0, ttl 64, id 42809, offset 0, flags [DF], proto TCP (6), length 227)
    localhost.http-alt > localhost.34890: Flags [P.], cksum 0xfed7 (incorrect -> 0x1ada), seq 1:176, ack 134, win 512, options [nop,nop,TS val 1104278852 ecr 1104278851], length 175: HTTP, length: 175
        HTTP/1.1 101 Switching Protocols
        Connection: Upgrade
        Upgrade: jboss-remoting
        Sec-JbossRemoting-Accept: ofI3qxa1miPoq1vhp3tDCO5r/kw=
        Date: Sat, 20 Jun 2020 22:16:08 GMT

与直接发送到 Wildfly 的请求相比,它们看起来相同。我不知道如何进一步调试。

有什么想法我可能做错了吗?

标签: nginxwildfly

解决方案


这是我的 nginx 配置的样子,它可以工作:

location / {
        proxy_pass              http://127.0.0.6:9990;
        proxy_http_version      1.1;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        Host $http_host;
        proxy_set_header        X-Forwarded-Proto $scheme;
        proxy_set_header        X-Frame-Options SAMEORIGIN;

        #for proxying wildfly
        proxy_set_header sec_jbossremoting_key $http_sec_jbossremoting_key;
        proxy_set_header sec_hornetqremoting_key $http_sec_hornetqremoting_key;
        proxy_set_header upgrade $http_upgrade;
        proxy_set_header connection "upgrade";
        proxy_set_header host $http_host;
    }

您可以通过执行jboss-cli.sh脚本进行调试,看看是否可以连接。

首先,尝试直接向wildfly发送请求,在我的例子中是127.0.0.6:9990

[user@server]# /opt/wildfly/bin/jboss-cli.sh --controller=127.0.0.6:9990 --connect
[standalone@127.0.0.6:9990 /] version
JBoss Admin Command-line Interface

然后,尝试通过 nginx 连接,在我的情况下是 172.16.20.11:9990

[user@server]# /opt/wildfly-8.2.1.Final/bin/jboss-cli.sh --controller=172.16.20.11:9990 --connect
[standalone@172.16.20.11:9990 /] version

运行脚本会告诉你你有什么样的错误,而不是 nginx :)


推荐阅读