Configuring Nginx support WebSocket Basic literature

Source: Internet
Author: User
Tags apache tomcat

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

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.