1

I'm working on a WebRTC video conferencing/remote performance site (built on an AWS "Lightsail" VM), and I've run into a very odd issue with PeerJS.

I'm hosting my own PeerJS server on port 3001, via an Apache2 reverse proxy. The reverse proxy seems to work correctly, because when peerjs.min.js hits '/peerjs/id' it returns an ID as expected.

However, subsequent calls to '/peerjs' that are made from inside the peerjs.min.js file instantly return a 404 error.

(I should note that my site works correctly if I simply use the default PeerJS server.)

So, for example, this request works as expected:

https://peer.improv-stage.com/peerjs/id

While this follow up request (which again, is kicked off from inside peerjs.min.js), results in a 404 error.

wss://peer.improv-stage.com/peerjs?key=peerjs&id=bd261271-09f7-44a3-a07e-3d3364c1989f&token=40sh9uviwb

(The id and token, parameters here are from a single invocation of the page, and will change on each visit, of course.)

I'm pretty sure it's a problem with my server setup, so, here's the info for that...

I'm invoking the Peer Server with the following command inside the htdocs directory:

peerjs --port 3001 --proxied true

And it replies with:

Started PeerServer on ::, port: 3001, path: / (v. 0.6.1)

And here's the relevant vhosts config from apache:

<VirtualHost *:443>
  ServerName peer.improv-stage.com

  DocumentRoot "/opt/bitnami/apache/htdocs"
  ProxyPass / http://127.0.0.1:3001/
  ProxyPassReverse / http://127.0.0.1:3001/

  SSLEngine on
  SSLCertificateFile "/opt/bitnami/letsencrypt/certificates/improv-stage.com.crt"
  SSLCertificateKeyFile "/opt/bitnami/letsencrypt/certificates/improv-stage.com.key"

  <Directory "/opt/bitnami/apache/htdocs">
    Options -Indexes +FollowSymLinks -MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

Another thing to note is that this lives on the same server as the site "Improv Stage" site itself. The improv stage site is a NodeJS app and it invokes the peer server (on the client side), with the following:

var myPeer = new Peer(undefined, {
host: 'peer.improv-stage.com',
port: 443,
secure: true,
path: "/",
debug: 3
})

I'm thinking that the solution will be to spin up another VM just for the Peer Server, but this entire thing bugs me. It should work, shouldn't it?

In any case, the site is currently live as I write this, and I'll leave it up and running until at least a few of you have had a look at it and offer some feedback. You can reach it at:

https://www.improv-stage.com/stackoverflow

Thanks for any ideas you can offer!

Diz

  • Hey Diz, Can you check if your Apache is configured for wss connection? I was playing around and I can see when your site tries to establish a wss connection it fails. `WebSocket connection to 'wss://peer.improv-stage.com/peerjs?key=peerjs&id=b844c034-a8db-47c2-ae8d-b9e096bef4cc&token=0454agryh446' failed: Error during WebSocket handshake: Unexpected response code: 404` When I tried to connect to a local instance of PeerServer, everything was working okay. – dHour Dec 24 '20 at 10:38
  • I thought WSS was just handled over TLS/SSL/443, but I will definitely check that to see if there's more to it than that. – Steven W. Disbrow Dec 24 '20 at 14:29
  • The only configuration item I could find to change was enabling `mod_proxy_wstunnel` but it didn't make any difference at all. (I tried changing my vhosts file to accommodate the change and that just made things worse.) If you have a sample configuration I could refer to, that would be helpful. – Steven W. Disbrow Dec 28 '20 at 15:57
  • Well. I threw in the towel on this and set up a dedicated TURN server. Initial testing seems to indicate that that's resolved my connection issues. – Steven W. Disbrow Dec 28 '20 at 21:27

1 Answers1

0

By adding this line of code to apache2 this problem solved for me:

     RewriteCond %{HTTP:Connection} Upgrade [NC]
     RewriteRule /(.*) ws://localhost:9500/$1 [P,L]

please note 9500 is the specific port that peerServer runs on it.

I have express and socket.io on port 3000 and peerServer on port 9500.

this answer helped a lot.

I think it is very dependent on web server configuration.

zahra_oveyedzade
  • 988
  • 10
  • 17