node.js - Nginx HTTP and 2 TCP on port 80 -


i doing have 2 websockets, 1 client , 1 server being used alongside http node server @ port 3000, doing wrong here? or not possible?

nginx config:

server {     listen 80;     server_name example.com;     location / {         proxy_pass http://localhost:3000/;         proxy_http_version 1.1;         proxy_set_header upgrade $http_upgrade;         proxy_set_header connection "upgrade";     }     location /ws/ {         proxy_pass http://localhost:8000/;         proxy_http_version 1.1;         proxy_set_header upgrade $http_upgrade;         proxy_set_header connection "upgrade";     }  } 

api.js

import opensocket 'socket.io-client'; const  socket = opensocket('ws://example.com/ws');  function roomsubscribe(roomid, cb) {     socket.on('roominfo', data => cb(null, data));     socket.emit('getroom', {'roomid': roomid}); }  function sendmessage(content) {     socket.emit('sendmessage', content); }  export { roomsubscribe, sendmessage }; 

i think should modify: delete upgrade settings in location /

and notice request path /ws, location regex in nginx.conf /ws/. keep same.

use socket :

socket = opensocket("ws://example.com/ws/", {transports: ['websocket']}) 

add code see whether ws connection build.

socket.on('connect', function () {   console.log('connected!'); }); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -