Openfire with nginx proxy

I am using nginx as reverse proxy to connect with openfire, but i get connection timeout if i try to connect with Spark client.
I tried ping between the docker services, ip and ports are connecting as expected.

nginx.conf

stream {
    upstream xmpps {
        server of_openfire:5222;
    }
    server {
        listen 5222;
        tcp_nodelay on;
        proxy_connect_timeout 30s; 
        proxy_timeout 30s; # Set this lower to be more flappy
        proxy_pass xmpps;
    }
    upstream xmpp {
        server of_openfire:5223;
    }
    server {
        listen 5223;
        tcp_nodelay on;
        proxy_connect_timeout 30s; 
        proxy_timeout 30s; # Set this lower to be more flappy
        proxy_pass xmpp;
    }


  upstream bosh {
        server of_openfire:7070;
    }
    server {
        listen 7070;
        tcp_nodelay on;
        proxy_connect_timeout 10s;
        proxy_timeout 30s;
        proxy_pass bosh;
    }

    upstream boshs {
        server of_openfire:7443;
    }
    server {
        listen 7443;
        tcp_nodelay on;
        proxy_connect_timeout 10s; 
        proxy_timeout 30s;
        proxy_pass boshs;
    }

}

docker-compose.yml

version: "3.3"

services:
  nginx:
    image: prod_nginx:v1
    networks:
      - backend
    ports:
      - "80:80"
      - "443:443"
      - "5223:5223"
      - "5222:5222"
      - "7070:7070"
      - "7443:7443"
    volumes:
      - ./nginx_conf:/etc/nginx/sites-enabled/:rw
      - ./letsencrypt:/etc/letsencrypt/
      - ./openfire:/var/lib/openfire:rw
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - node.role == manager

  openfire:
    image: prod_openfire:v1
    ports:
      - "9090:9090"
      - "55222:5222"
      - "55223:5223"
      - "57070:7070"
      - "57443:7443"
    volumes:
      - ./openfire:/var/lib/openfire:rw
      - ./letsencrypt:/etc/letsencrypt/
    networks:
      - backend

networks:
  backend:
    driver: overlay

I know it’s a little late, but here’s what worked for me! I only needed my Spark client to connect and I didn’t need web access. If you need web access, you can simply configure your reverse http proxy as such.

# Note: this location is assuming you're using the nginx container image
load_module '/etc/nginx/modules/ngx_stream_js_module.so';
stream {
    server {
        listen 5222;
        proxy_protocol on;
        proxy_pass 192.168.X.X:5222;
    }
}