Configuring Nginx support WebSocket Basic literature
Nginx is a popular Web server system, the market share is about to surpass the second-ranked IIS, currently, the world's most visited sites, 30% use Nginx. Therefore, support for WebSocket is a very large requirement in the Nginx community. Nginx supports WebSocket, which allows users to extend and simplify nginx-based real-time web applications and platforms.
WebSocket is a new protocol in HTML5 that enables full-duplex communication between the browser and the server . In traditional Web services, in order to achieve instant communication, the technology used is polling (polling), at a specific time interval (for example, every 1 seconds), the browser sends an HTTP request to the server, and then the server returns the latest data to the client browser. This allows the browser to constantly make requests to the server, which can consume a lot of bandwidth.
Through the WebSocket API, the browser and server only need to do a handshake, and then, the browser and the server formed a fast channel, you can directly transfer data to each other.
Reference Link: http://nginx.org/en/docs/http/websocket.html
HTTP {
.....
Map $http _upgrade $connection _upgrade {
Default upgrade;
"Close;
}
server {
...
location/chat/{
Proxy_pass Http://backend;
Proxy_http_version 1.1;
Proxy_set_header Upgrade $http _upgrade;
Proxy_set_header Connection $connection _upgrade;
}
}
/opt/server/nginx/sbin/nginx-v to view Nginx version
Nginx version:nginx/1.4.7
/OPT/SERVER/NGINX/SBIN/NGINX-T Check nginx configuration file
/etc/init.d/nginx Restart Restart Nginx
Note:
On the server side, there are also some projects that implement the WebSocket protocol:
Apache Tomcat 7.0.27 version
Nginx 1.3.13 version
Jwebsocket Java Implementation version
This article is from the "Youth Deng Yong" blog, please be sure to keep this source http://dengyong.blog.51cto.com/8409869/1566120
Configuring Nginx support WebSocket Basic literature