使用Nginx的NHPM模块和jQuery进行的Comet测试

本文介绍了一个基于Nginx和jQuery的Comet技术实践案例。通过安装配置CentOS环境下的Nginx并结合jQuery,实现了简单的实时消息推送功能。具体步骤包括下载安装软件、配置Nginx、创建HTML测试页面等。

原文在这里:http://blog.jamieisaacs.com/2010/08/27/comet-with-nginx-and-jquery/ 

一直很想了解Comet的实现,正好看见了上面的这个文章,就装了个CentOS做了一下实验,过程如下: 

1、下载软件和安装 引用wget http://pushmodule.slact.net/downloads/nginx_http_push_module-0.692.tar.gz tar -xvzf nginx_http_push_module-0.692.tar.gz wget http://nginx.org/download/nginx-0.8.52.tar.gz tar -xvzf nginx-0.8.52.tar.gz ./configure --prefix=/usr/local/nginx --add-module=/root/nginx_http_push_module-0.692 make sudo make install configure过程中会提示哪些包没有,我的就是pcre-devel包没有,直接使用光盘rpm 安装上就可以了 

2、配置文件,修改nginx的配置文件nginx.conf,并启动nginx 引用#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 81; server_name localhost; root /var/www/localhost; location /cheetah { push_channel_group pushmodule_cheetah; location /cheetah/pub { set $push_channel_id cheetah; push_publisher; push_message_timeout 5s; # Give the clients time push_message_buffer_length 10; # to catch up } location /cheetah/sub { set $push_channel_id cheetah; push_subscriber; send_timeout 3600; } } } } 启动nginx 引用/usr/local/nginx/sbin/nginx 

3、编辑html测试文件,send.html用来发送信息,listen.html则是接受信息,当然保证jquery在相应的目录中。 send.html

大功告成,只要在send.html里面输入内容并发送,listen.html就会接收到信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值