015_nginx as the WebSocket proxy setting

Source: Internet
Author: User

Production and research there is the need for long connection through Nginx Proxy, we know that the default Nginx only supports short connections, with long connections need to be configured separately

One

The WebSocket protocol provides a Web application that creates a two-way communication that supports both server and client. As part of the HTML5, Websock makes it easier to provide a simpler method than the way it was previously available. Most of today's browsers support Websock, including chrome,firefox,internet browsers, Opera, and Safari, and a growing number of server application frameworks are also beginning to support Websock.

The WebSocket protocol is different from the HTTP protocol, but the WebSocket handshake is HTTP compatible and updates the connection from HTTP to upgrade with the TTP Websock method. This allows WebSocket applications to more easily fit into existing infrastructures. For example, Websock apps can communicate using standard HTTP ports 80 and 443.

       a WebSocket application keeps A long?running connection open between the client and the Serv Er, facilitating the development of real?time applications. This  http Upgrade mechanism by using " THE  Upgrade  and  Connection   Headers. "To update the connection from HTTP to WebSocket. There is some challenges, a reverse proxy server faces in supporting WebSocket. One is WebSocket is a hop-by-hop (hop) protocol,  SO when a proxy server intercepts an Upgrade request from a client it needs to send It own Upgrade request to the backend server, including the appropriate headers. Also, the WebSocket connection is a long connection, rather than a typical short connection when using HTTP, that is, the reverse proxy server needs to keep these connections open when they are idle, rather than shutting them down.

NGINX supports WebSocket by allowing a tunnel to BES set up between a client and a backend server. For Nginx sending upgrade requests from client to backend server, the and Upgrade Connection headers must be set explicitly, as in this example:

location/wsapp/{    Proxy_pass http://wsbackend;    Proxy_http_version 1.1;    Proxy_set_header Upgrade $http _upgrade;    Proxy_set_header Connection "Upgrade";}

Once This is do, NGINX deals with this as a WebSocket connection.

Two, give a chestnut.

Reference: https://www.nginx.com/blog/websocket-nginx/

015_nginx as the WebSocket proxy setting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.