title: Config nginx to reverse proxy for mqtt communication
body: <p>I have an MQTT (EMQX) server running on an ip and a port. And I communicate directly between my service and that port using the nodejs MQTT library.</p>
  <p>I want to use a reverse proxy (nginx) to be able to use a DNS in order to prune the communication.</p>
  <p>At this moment my nginx is configured like this:</p>
  <pre><code>events { worker_connections 1024; }
  
  stream {
  
      upstream websocket {
          server ******:7053;
      }
   
      server {
  
          listen 8888;
   
          proxy_pass websocket;
  
  
      }
  }
  
  http {
  
      server {
          
          listen 884;
          server_name *******;.
          error_log /var/log/errors.log;
          
          location / {
              proxy_pass *******;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection &quot;upgrade&quot;;
              proxy_set_header Host $host;
  
          }
  
      } 
  
  }
  </code></pre>
  <p>So when I try to connect through port 8888 the nginx always timeout</p>
  <pre><code>2020/12/03 16:23:48 [error] 22#22: *31 upstream timed out (110: Connection timed out) while connecting to upstream, client: 89.155.0.10, server: 0.0.0.0:8888, upstream: &quot;192.16.102.26:7053&quot;, bytes from/to client:0/0, bytes from/to upstream:0/0
  </code></pre>
  <p>both services are in docker containers. and are started by a docker compose.</p>
  <p>the compose for MQTT service is:</p>
  <pre><code>version: &quot;2.1&quot;
  
  
  services:
  
    mqtt-broker:
      build:
        context: .
        dockerfile: Dockerfile
      container_name: evio_mqtt_broker
      environment:
        - EMQX_LISTENER__SSL__EXTERNAL=8883
        - EMQX_DASHBOARD__LISTENER__HTTP=18083
  
        - EMQX_LOADED_PLUGINS=&quot;emqx_auth_username,emqx_recon,emqx_retainer,emqx_management,emqx_dashboard&quot;
  
        - EMQX_LISTENER__SSL__EXTERNAL__TLS_VERSIONS=tlsv1.2
        #- EMQX_LISTENER__SSL__EXTERNAL__KEYFILE=etc/certs/key.pem
        #- EMQX_LISTENER__SSL__EXTERNAL__CERTFILE=etc/certs/cert.pem
        #- EMQX_LISTENER__SSL__EXTERNAL__CACERTFILE=etc/certs/cacert.pem
        - EMQX_LISTENER__SSL__EXTERNAL__VERIFY=verify_peer
        #- EMQX_LISTENER__SSL__EXTERNAL__FAIL_IF_NO_PEER_CERT=true
        - EMQX_LISTENER__SSL__EXTERNAL__REUSE_SESSIONS=on
        - EMQX_LISTENER__SSL__EXTERNAL__HONOR_CIPHER_ORDER=on
  
        - EMQX_ALLOW_ANONYMOUS=false
        - EMQX_AUTH__USER__1__USERNAME=****
        - EMQX_AUTH__USER__1__PASSWORD=****
        #- EMQX_AUTH__USER__2__USERNAME=umdc
        #- EMQX_AUTH__USER__2__PASSWORD=umdc_buddy
  
        - EMQX_DASHBOARD__DEFAULT_USER__PASSWORD=****
      ports:
        - &quot;7053:1883&quot;   # MQTT Port
        - &quot;8883:8883&quot;   # MQTT SSL Port
        #- &quot;8083:8083&quot;   # MQTT WebSocket Port
        #- &quot;8084:8084&quot;   # MQTT WebSocket SSL Port
        #- &quot;8080:8080&quot;   # HTPP Management Port
        - &quot;1884:18083&quot; # Web Dashboard Port
      logging:
        driver: &quot;json-file&quot;
        options:
          max-size: &quot;50m&quot;
          max-file: &quot;3&quot;
      networks:
        - evio_network
      stop_signal: SIGKILL
  
  networks:
      evio_network:
  </code></pre>
  <p>and for nginx are:</p>
  <pre><code>version: &quot;2.0&quot;
  
  networks:
    evio_network:
  
  services:
    reverse_proxy:
      container_name: reverse_proxy
      image: nginx
      networks:
        - evio_network
      ports:
        - 8888:8888
        - 8843:8843
        - 1883:1883
        - 8883:8883
      volumes:
        - /home/evio/src/evio_nginx_reverse_proxy/config/nginxDEV.conf:/etc/nginx/nginx.conf
      restart: always
  </code></pre>
  <p>Do I have to change anything in mqtt or is something wrong with my reverse proxy?</p>