您需要配置订阅和发布的端点。将以下内容添加到您的 nginx.conf 文件中:
# internal publish endpoint (keep it private / protected)
location /publish {
set $push_channel_id $arg_id; #/?id=239aff3 or somesuch
push_publisher;
push_store_messages on; # enable message queueing
push_message_timeout 2h; # messages expire after 2 hours, set to 0 to never expire
push_message_buffer_length 10; # store 10 messages
}
# public long-polling endpoint
location /subscribe {
push_subscriber;
# how multiple listener requests to the same channel id are handled
# - last: only the most recent listener request is kept, 409 for others.
# - first: only the oldest listener request is kept, 409 for others.
# - broadcast: any number of listener requests may be long-polling.
push_subscriber_concurrency broadcast;
set $push_channel_id $arg_id;
default_type text/plain;
}
查看文档
http://www.brentsowers.com/2011/06/http-long-polling-aka-comet-with-nginx.html
http://www.igvita.com/2009/10/21/nginx-comet-low-latency-server-push/
如果您想将其转换为完整的COMET
服务器,您可以使用
https://github.com/slact/nginx_http_push_module