1. 下载
http://pushmodule.slact.net/downloads/nginx_http_push_module-0.69.tar.gz
2. 编译nginx
1).解压nginx_http_push_module
tar -zxvf nginx_http_push_module-0.69.tar.gz
2).编译安装nginx_http_push_module
# ./configure --prefix=/usr/local/$NAME --sbin-path=/usr/local/sbin/$NAME.$VERSION --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.8.x.pid --http-log-path=/var/log/nginx/8.x.access.log --error-log-path=/var/log/nginx/8.x.error.log --user=nginx --group=nginx --with-openssl=/usr/lib/ssl/ --with-http_stub_status_module --with-http_flv_module --with-http_sub_module --add-module=/to/path/nginx_http_push_module
# sudo make
# sudo make install
3. 添加 nginx conf
location /pub {
set $push_channel_id $arg_id; #/?channel=239aff3 or some-such
push_publisher;
push_message_timeout 2h; # expire buffered messages after 2 hours
push_max_message_buffer_length 10; # store absolutely at most 10 messages
push_min_message_recipients 0; # minimum recipients before purge
}
location /sub {
set $push_channel_id $arg_id;
push_subscriber;
# how multiple subscriber requests to the same channel id are handled
# - last: only the most recent subscriber request is kept, 409 for others.
# - first: only the oldest subscriber request is kept, 409 for others.
# - broadcast: any number of subscriber requests may be long-polling.
push_subscriber_concurrency broadcast;
#/?channel=239aff3 or some-such
default_type text/plain;
}
4. http 客户端 例子
<javascript type="text/javascript" src="chat/mootools-1.2.4.js"/>
<javascript type="text/javascript" src="chat/dumbchat.js"/>
<link rel="stylesheet" type="text/css" href="http://pushmodule.slact.net/style.css" />
<script type="text/javascript">
window.addEvent('load', function() {
var chatEl = document.getElement("div.chat");
//autocomplete off
chatEl.getElements("form input[type=text]").each(function(el){
el.set('autocomplete', 'off');
});
var dummy = new Dumbchat(chatEl.getElement("form"), chatEl.getElement("ul"), "http://www.domain.com/sub?id=1", Cookie.read('chatname')).connect();
//user renaming stuff
Cookie.write('chatname', dummy.username, {domain: "/"});
function rename(ev) {
if (this.get('value')!=dummy.username) {
dummy.rename(this.get('value'));
Cookie.write('chatname', dummy.username, {domain:"/"});
}
}
chatEl.getElement("form input[name=username]").set('value', dummy.username).addEvents({
'blur': rename,
'keydown': function(ev) {
if(ev.key=="enter") {
ev.stop();
rename.bind(this)();
}
}
});
//disconnect on unload
['unload', 'beforeunload'].each(function(name) {
window.addEvent(name, function(){
dummy.disconnect();
});
});
if(Browser.Engine.trident) { //curse you, Internet Explorer!
chatEl.getElement("form input[name=message]").addEvent('keydown', function(ev) {
if(ev.key=='enter') {
ev.stop(); //i guess
chatEl.getElement("form").fireEvent('submit');
}
});
}
});
</script>
<div class="chat">
<ul>
<li class="notice">Here's an example chat application. It's made entirely with .</li>
</ul>
<form method="post" id="chatform" action="http://www.domain.com/pub?id=1">
<input class="submit" type="submit" value="send" />
<input type="text" class="username" name="username" maxlength="9" />说: <input type="text" class="message" name="message" />
</form>
</div>
链接地址http://pushmodule.slact.net/
posted on 2009-11-20 11:29
冰是没有未来的,因为它的永恒 阅读(1178)
评论(0) 编辑 收藏 所属分类:
nginx