title: How to convert a HTTP stream to HTTPS?
body: <p>My website is running via HTTPS at a public hoster and connects to a node server that is running on a Raspberry PI.</p>
  
  <p>There is also a piece of hardware (lets call it decoder) in the same network with the PI which sends a data stream via TCP. The purpose of the PI is to read that stream and send it via <code>WebSocket</code> to the browser. So the goal is to output that stream on my website.</p>
  
  <p>Now I'm running in a mixes content problem and have no idea how to solve it.</p>
  
  <p>What I have done so far is to install an <code>nginx</code> webserver on the PI and have installed a Letsencrypt certificate. Both are running fine (tested via normal https:// call in a webbrowser).</p>
  
  <p>The Websocket connection <strong>without</strong> SSL works fine as well and I get the data, but <strong>with</strong> SSL wont work. I guess that the problem is, that the decoder is not able to handle SSL.</p>
  
  <p>So how can I "send", "convert", "tunnel" or "proxy" the non-SSL data stream to a HTTPS server?</p>
  
  <p><strong>Update</strong></p>
  
  <p>@Jake Holzinger: you are absolutely right. The given information was not enough. Sorry! I try to clarify:</p>
  
  <ol>
  <li><code>nginx</code> is without any further modification. So it is the configuration which comes from the installation</li>
  <li>the website (Angular) does a <code>let connection = new WebSocket('wss://domain:port');</code></li>
  <li><p>The node server looks like follows:</p>
  
  <pre><code>const net = require('net');
  const fs = require('fs');
  const https = require('https');
  const date = require('date-and-time');
  const config = require('./server-config.json');
  const httpProxy = require('http-proxy');
  
  //  SSL SERVER
  try {
      const privateKey = fs.readFileSync('/etc/letsencrypt/live/' + config.DNSROUTER + '/privkey.pem', 'utf8');
      const certificate = fs.readFileSync('/etc/letsencrypt/live/' + config.DNSROUTER + '/cert.pem', 'utf8');
      const ca = fs.readFileSync('/etc/letsencrypt/live/' + config.DNSROUTER + '/chain.pem', 'utf8');
  
      const options = {
              key: privateKey,
              cert: certificate,
              ca: ca
      };
  
      let proxy = httpProxy.createServer({
          target: 'ws://localhost:9030',
          ssl: {
              key: privateKey,
              cert: certificate
          }
      }).listen(9031);
  }
  catch (e) {
      console.log("LETSENCRYPT certificates not found! No SSL!");
      console.log(e)
  }
  
  /**
   *  server
   */
  let connections = {};
  let WebSocketServer = require('ws').Server;
  
  // start WS via HTTP
  const wss1 = new WebSocketServer({port: 9030});
  
  wss1.on('connection', function(ws) {
      CLIENTS.push(ws);
      console.log('connection via HTTP');
  
      ws.on('close', function () {
          console.log('close HTTP!');
          CLIENTS = CLIENTS.filter(item =&gt; item != ws);
      })
  })
  
  
  /**
   *  client
   */
  let connect = function() {
  
                  console.log(now(), 'Starting server...');
  
                  const socket = net.createConnection({ port: config.PORT, host: config.HOST }, () =&gt; {
                      console.log('Connected to server!');
                  })
  
                  socket.on('connect', () =&gt; {
                      console.log(now(), 'Connected to server!');
  
                      socket.on('data', data =&gt; {
                          sendAll(data);
                      });
                  });
  
                  socket.on('error', data =&gt; {
                      console.log(now(), "Connnection refused:", data.errno,data.code,"(IP:", data.address + ":" + data.port + ")");
  
                      setTimeout(() =&gt; {
                          socket.removeAllListeners();
  
                          console.log(now(),"Reconnecting...");
                          connect();
                      }, 1000);
                  });
  
                  socket.on('end', () =&gt; {
                      console.log(now(), 'Disconnected from server');
                      console.log(now(), "Reconnecting...");
  
                      socket.removeAllListeners();
                      connect();
                  });
  }
  
  connect();
  </code></pre></li>
  </ol>
  
  <p>I hope that this will get a better impression. Thx for your help!</p>