Git Product home page Git Product logo

Comments (4)

dswarbrick avatar dswarbrick commented on August 20, 2024

I've run into this issue with Apache's mod_proxy too. However, are you sure that your websocket will even work via Nginx's proxy module? Websockets require full-duplex communication, and I suspect that most proxies only support a single request/response pair.

from gevent-socketio.

abourget avatar abourget commented on August 20, 2024

Exactly. Nginx doesn't forward all the headers (because it seems Websocket isn't fully HTTP/1.1 compliant) and it doesn't allow for full negotiation of the websocket. Thus, 'wsgi.websocket' isn't inserted in the environment (that's where you get your KeyError). Also, I don't think Nginx is ready to do full-duplex either.

I know it is possible to configure HAProxy to forward everything to the gevent server, so I would suggest looking in that direction.

Since this ticket isn't related to a bug in gevent-socket, I'm going to close it.

Hope this helps.

from gevent-socketio.

laginha avatar laginha commented on August 20, 2024

Nginx supports websockets as you can see here. I've tested it in front of a simple Node.JS server and with Socket.io client. It worked!

Now, in a project i'm currently working on, I'm running Gunicorn + gevent-socketio as recommended in the docs. No problem there. However I've tried to set Nginx up with SSL enabled, like this:

server {
    listen      443;
    server_name  events.hostname;
    ssl on;
    ssl_certificate /path/to/x.crt;
    ssl_certificate_key /path/to/x.key;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout  5m;
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        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 https;
        proxy_redirect off;
    }
}

Without success.
Every time my Socket.io client tries to connect, it receives a 500 status code due to the KeyError: 'wsgi.websocket' exception. I guessed the "Upgrade" header was missing, which I find weird.

So i changed the configuration a little bit and set the header manually proxy_set_header Upgrade "websocket". As a result the exception is raised no-more. However after a while i get this error Error during WebSocket handshake: 'Upgrade' header is missing on my javascript console.

Dispite this problem may not be related to a bug in gevent-socket, I would appreciate any help. Any ideias of what might be wrong? Am I missing anything?

from gevent-socketio.

jensenw avatar jensenw commented on August 20, 2024

I use Gunicorn + nginx1.4.1 ,and add my nginx.conf

   location / {
                   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                   proxy_set_header Host $http_host;

                   proxy_redirect off;

                   proxy_pass http://127.0.0.1:8082/;
                   proxy_http_version 1.1;
                   proxy_set_header Upgrade $http_upgrade;
                   proxy_set_header Connection "upgrade";
                    }

when running the code, I keep get this error " KeyError: 'wsgi.websocket' " ,but application stil work and it's little bit slow when trying to connect websocket .

after googling then i'm installing nginx-full and my problem solved ,hope this can help.

from gevent-socketio.

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.