This is excellent. I've been looking to better understand what is going on with WebSockets and Nginx. This is certainly one of the best explanations available on you tube, most simply say copy this code and paste it into locations.
Thank you so much, You don't know how I spent the last 7 days in nightmare with that problem, Finally I found you, You deserve more than a subscribe and a like. P.S: Do you have a Patreon or something like that you must get at least some appreciation.
Can you do this with an another Node process, over a different port....Or it needs to be 8080? Is it possible for example to have another location block, where you would proxy pass websocet connection , over maybee 4000?
Hi, I am facing issue in same scenario. Could you please guide me in this. I have react application which connects to tomcat server using nodejs server. On server all the API logic is implemented and now I want to implement websocket which will first connect to node server then tomacat server. I just know the there should be a tunneling logic needs to be implemented but I don't know how to do that. Could you please help me in this.
To be honest I have never tried it in production, however it looks like Nginx has "http2" flag that should make things "just work". The server configuration block should look like "listen 443 ssl http2 default_server;" to have both SSL and HTTP2. Disclaimer: haven't tried it and don't know if it will work :)
can anyone help me i making a microservice to handle 50k concurrent request on node js and socket io i want to divide the load on multiple connection and those connection should not close or die when user leave all 50k connection should me maintaind
Hmm, not quite sure how this is supposed to work though. If the user leaves and closes their side of the connection, the connection will be closed. Overall, I would recommend looking at something that has auto-scaling, for example AWS API Gateway + Lambdas, if the load is spiky and you need elasticity. For experimental purposes I found this article insightful: unetworkingab.medium.com/millions-of-active-websockets-with-node-js-7dc575746a01
Thanks for your awesome videos I have a graphql nodejs server which have just one endpoint. So how can I set up both http and websocket on one location. Because graphql only have one endpoint
how about import { WebSocketLink } from "apollo-link-ws"; import { HttpLink } from "apollo-link-http"; import { split } from "apollo-link"; import { getMainDefinition } from "apollo-utilities"; const httpLink = new HttpLink({ uri: "hasura-infiite-loader.herokuapp.com/v1alpha1/graphql" // use https for secure endpoint }); // Create a WebSocket link: const wsLink = new WebSocketLink({ uri: "ws://hasura-infiite-loader.herokuapp.com/v1alpha1/graphql", // use wss for a secure endpoint options: { reconnect: true } }); // using the ability to split links, you can send data to each link // depending on what kind of operation is being sent const link = split( // split based on operation type ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === "OperationDefinition" && operation === "subscription"; }, wsLink, httpLink );
nginx is executed as user "nginx" it also has very limited permissions. When you run > systemctl start nginx, the script switches from "root" to "nginx" user if that makes sense.
I think you just helped me out tremendously. I use application manager for jump starting my node application which support showed me. However it doesn't work with websockets on my socket.io app that I have. I have many php applications running and don't want to disturb them so doing ngnix would need to be not disturbing my apache applications. I did your video earlier and killed all my php applications so I have ngnix installed but it's disabled. How can I do this same process just on apache to get websockets work. I have been looking for months and this is the closet video I could find even touching basis on my most biggest hurdle in development yet. It has halted all my nodejs applications because webrtc is the only reason I want to use node and because I can't get sockets configured on my centos 7 machine I have stopped for over 6 months now. Please advise you or anyone.
@@jack82822005 we don't :) we choose which HTTP version will proxy use. 1.1 is currently the most reasonable choice. The other option would be 2.0, but HTTP2 is a whole different story. Don't worry, HTTP 1.1 was released in 1997, so everything supports it.
I _ L O V E _ U _ S O _ M U CH _ ! i struggled since 2 Days with my Ubunto 18.04 Server and Polling. Now i have a great WebSocket-Connection and my game runs sooooo smooth now