Giter VIP home page Giter VIP logo

Comments (7)

goriunov avatar goriunov commented on June 9, 2024

@carmas123 i have done some tests on my local machine and everything works properly (PS done tests only with ws). Just to note nginx is very strict with url / ending:

My working example:

server {
   listen: 3000;
   server_name: localhost;

   location /ws/ {
        access_log on;
        proxy_pass http://127.0.0.1:3001/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Proxy "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        proxy_set_header X-NginX-Proxy true;
        proxy_cache_bypass $http_upgrade;
    }
}

// JS client connects to 
let socket = new ClusterWS({
  url: `ws://127.0.0.1:3000/ws/`
})

// ClusterWS 4 server specifies WSPath as `/`

new ClusterWS({
     ....
     websocketOptions: {
           wsPath: "/",
     }
     ....
})

As soon as i remove even one / anywhere, i will get broker connection with error 400 or 502. Please make sure you have correct urls everywhere including / at the end.

Broken Examples:

   location /ws/ {
        access_log on;
        proxy_pass http://127.0.0.1:3001;  <- Note just removed `/` and it is broken
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Proxy "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        proxy_set_header X-NginX-Proxy true;
        proxy_cache_bypass $http_upgrade;
    }

// JS client connects to 
let socket = new ClusterWS({
  url: `ws://127.0.0.1:3000/ws/`
})

Or

   location /ws/ {
        access_log on;
        proxy_pass http://127.0.0.1:3001/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Proxy "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        proxy_set_header X-NginX-Proxy true;
        proxy_cache_bypass $http_upgrade;
    }

// JS client connects to 
let socket = new ClusterWS({
  url: `ws://127.0.0.1:3000/ws` <- Just remove `/` and it does not work any more
})

Would suggest to try playing around with configs and correct path configurations also try changing localhost to 127.0.0.1 and otherwise to see if that will help.

Let me know how it goes 😄

from clusterws.

carmas123 avatar carmas123 commented on June 9, 2024

I solved and I'll tell you later a fullworking solution. With Nginx we need to rewrite the $schema

from clusterws.

goriunov avatar goriunov commented on June 9, 2024

👍

from clusterws.

carmas123 avatar carmas123 commented on June 9, 2024

Ok, I solved adding this string into location key of Nginx:
proxy_redirect https:// $scheme://;

Happy coding to all :)

from clusterws.

goriunov avatar goriunov commented on June 9, 2024

@carmas123 Thanks will keep in mind I am going to pin this issue.

from clusterws.

carmas123 avatar carmas123 commented on June 9, 2024

I think that this is not a ClusterWS problem, but this occurs because web socket filter only wss/ws schema to handle websocket and other to handle all other requests.
If nginx translate the source wss:// schema to https:// obviously it does not work.

from clusterws.

goriunov avatar goriunov commented on June 9, 2024

Yes, that would be still very useful to keep pinned as question there are surely would be others who can have similar problem with Nginx configs as it is very popular proxy 😄

from clusterws.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.