title: (peerjs) I'm trying to get my peerjs server work through nginx/ssl but its just not working
body: <p>I'm not sure what the issue is here<br />
  Site (in case the console is useful): https://ale-bot.xyz<br />
  my nginx website config file:</p>
  <pre><code>server {
      listen                  443 ssl http2;
      listen                  [::]:443 ssl http2;
      server_name             ale-bot.xyz;
      root            /var/www/ale-bot.xyz/;
  
      # SSL
      ssl_certificate         /etc/letsencrypt/live/ale-bot.xyz/fullchain.pem;
      ssl_certificate_key     /etc/letsencrypt/live/ale-bot.xyz/privkey.pem;
      ssl_trusted_certificate /etc/letsencrypt/live/ale-bot.xyz/chain.pem;
  
      # security
      include                 nginxconfig.io/security.conf;
  
      # logging
      access_log              /var/log/nginx/ale-bot.xyz.access.log;
      error_log               /var/log/nginx/ale-bot.xyz.error.log warn;
  
      location /test {
          return 200 'ok';
      }
  
      # reverse proxy
      location / {
          proxy_pass http://127.0.0.1:8080;
          include    nginxconfig.io/proxy.conf;
      }
  
      location /peer/:room {
          proxy_pass http://127.0.0.1:9000;
      }
  
      # additional config
      include nginxconfig.io/general.conf;
  }
  
  # subdomains redirect
  server {
      listen                  443 ssl http2;
      listen                  [::]:443 ssl http2;
      server_name             *.ale-bot.xyz;
  
      # SSL
      ssl_certificate         /etc/letsencrypt/live/ale-bot.xyz/fullchain.pem;
      ssl_certificate_key     /etc/letsencrypt/live/ale-bot.xyz/privkey.pem;
      ssl_trusted_certificate /etc/letsencrypt/live/ale-bot.xyz/chain.pem;
      return                  301 https://ale-bot.xyz$request_uri;
  
      location /test {
          return 200 'ok';
      }
  
  }
  
  # HTTP redirect
  server {
      listen      80;
      listen      [::]:80;
      server_name .ale-bot.xyz;
      include     nginxconfig.io/letsencrypt.conf;
  
      location / {
          return 301 https://ale-bot.xyz$request_uri;
      }
  
      location /test {
          return 200 'ok';
      }
  
  }
  </code></pre>
  <p>and my server.js file...</p>
  <pre class="lang-js prettyprint-override"><code>const express = require('express')
  const app = express()
  const server = require('http').Server(app)
  const io = require('socket.io')(server)
  const port = 8080
  const { v4: roomID } = require('uuid')
  const connections = new Map()
  const fs = require('fs')
  const { PeerServer } = require('peer')
  
  app.set('view-engine', 'ejs')
  app.use(express.static('public'), express.urlencoded({ extended: false }))
  
  app.get('/', (req, res) =&gt; {
      res.render('welcome.ejs')
  })
  
  app.post('/finding_keys', (req, res) =&gt; {
      const { input } = req.body
      if (!input || !connections.get(input)) {
          res.status(200)
          return res.redirect('/')
      } else {
          res.redirect('/peer/'+input)
      }
  })
  
  app.get('/unlocking_door', (req, res) =&gt; {
      res.redirect(`/peer/${roomID()}`)
  })
  
  app.get('/peer/:room', (req, res) =&gt; {
      res.setHeader('content-type', 'text/html');
      res.render('room.ejs', { roomID: req.params.room })
  })
  
  io.on('connection', socket =&gt; {
      socket.on('join-room', (roomID, userID) =&gt; {
          socket.join(roomID)
          socket.to(roomID).broadcast.emit('user-connected', userID)
  
          connections.set(roomID, true)
  
          socket.on('disconnect', () =&gt; {
              socket.to(roomID).broadcast.emit('user-disconnect', userID)
          })
      })
  })
  
  server.listen(port, () =&gt; { console.log(`listening on port ${port}`) })
  </code></pre>
  <p>my script.js file:</p>
  <pre class="lang-js prettyprint-override"><code>const socket = io('/');
  const videoGrid = document.getElementById('video-grid');
  const peer = new Peer({
      port: 9000,
      path: '/peer/:room',
      proxied: true
  });
  
  const myVideo = document.createElement('video');
  myVideo.muted = true;
  const peers = {}
  
  navigator.mediaDevices.getUserMedia({
      video: true,
      audio: true
  }).then(stream =&gt; {
      addVidStream(myVideo, stream)
  
      peer.on('call', call =&gt; {
          call.answer(stream)
  
          const video = document.createElement('video')
  
          call.on('stream', uStream =&gt; {
              addVidStream(video, uStream)
          })
      })
  
      socket.on('user-connected', userID =&gt; {
          connectToUser(userID, stream)
      })
  })
  
  socket.on('user-disconnect', userID =&gt; {
      if (peers[userID]) peers[userID].close()
  })
  
  peer.on('open', ID =&gt; {
      socket.emit('join-room', connection.IDs.room, ID);
  });
  
  function connectToUser(userID, stream) {
      const call = peer.call(userID, stream)
      const video = document.createElement('video')
      call.on('stream', uStream =&gt; {
          addVidStream(video, uStream)
      })
      call.on('close', () =&gt; {
          video.remove()
      })
  
      peers[userID] = call
  }
  
  function addVidStream(video, stream) {
      video.srcObject = stream
      video.addEventListener('loadedmetadata', () =&gt; {
          video.play()
      })
      videoGrid.append(video)
  }
  </code></pre>
  <p>And I run the server from the console like this:</p>
  <pre><code>peerjs --port 9000 --path /peer/:room --proxied true
  </code></pre>
  <p>If you need any more info ask away, I've been stuck for a couple of days and it's been more and more frustrating for me.</p>