| May | JUN | Jul |
| 07 | ||
| 2021 | 2022 | 2023 |
COLLECTED BY
Collection: Save Page Now Outlinks
Server push is more efficient and scalable than long polling because the
web browser does not have to constantly ask for updates through a stream
of AJAX requests.
While the above diagram shows a server pushing data to the client, WebSockets
is a full-duplex connection so the client can also push data to the server
as shown in the diagram below.
The WebSockets approach for server- and client-pushed updates works well for
certain categories of web applications such as chat room, which is why that's
often an example application for a WebSocket library.
# this is where my WSGI server sits answering only on localhost # usually this is Gunicorn monkey patched with gevent upstream app_server_wsgiapp { server localhost:5000 fail_timeout=0; } server { # typical web server configuration goes here # this section is specific to the WebSockets proxying location /socket.io { proxy_pass http://app_server_wsgiapp/socket.io; proxy_redirect off; 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_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_read_timeout 600; } }Note if you run into any issues with the above example configuration you'll want to scope out the official HTTP proxy module documentation. The following resources are also helpful for setting up the configuration properly. Nginx has an official page for WebSocket proxying. Proxying WebSockets with Nginx shows how to proxy with Socket.io.