Nginx Nchan消息发布安装及使用

Nchan消息推送、发送client,文档参考请点击
Nchan安装配置(为防止出现权限问题, 建议直接用root用户安装 )
1、下载Nginx和Nchan 
[root@node10 ~]# wget http://nginx.org/download/nginx-1.8.1.tar.gz
[root@node10 ~]# tar -zxvf nginx-1.8.1.tar.gz
[root@node10 ~]# git clone https://github.com/slact/nchan.git
2、安装一些依赖包
[root@node10 ~]# sudo apt-get install build-essential zlib1g-dev libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgd2-xpm-dev libgeoip-dev libgoogle-perftools-dev libperl-dev
3、编译安装(在nginx 目录中 ) 
[root@node10 ~]# cd nginx-1.8.1
[root@node10 nginx-1.8.1]# ./configure --add-module=/root/nchan
[root@node10 nginx-1.8.1]# make && make install
4、配置 nginx.conf
worker_processes auto;


worker_rlimit_core 1024M;
worker_rlimit_nofile 100000;

events {
  worker_connections 500000;
  use epoll;
}


http {

  log_format nchan '$nchan_channel_id $nchan_subscriber_type $nchan_publisher_type $nchan_message_id $nchan_prev_message_id';

  access_log /var/log/nginx/nchan_access.log;

  error_log /var/log/nginx/nchant_error.log;

  nchan_subscribe_existing_channels_only off;
  nchan_max_reserved_memory 32M;

  client_max_body_size 1m;


  server {
    listen 80 default_server;
    #listen 9443 ssl;
    #ssl_certificate /usr/local/nginx/ssl/server.crt;
    #ssl_certificate_key /usr/local/nginx/ssl/server.key;
    server_name localhost;


    location ~ /pubsss/(\w+)$ {

      nchan_channel_id $1;
      #nchan_channel_events_channel_id 'events/pubftl/$1';
      nchan_publisher http;
      nchan_message_timeout 240s;
      nchan_channel_group test;
    }

    location ~ /sub/(\w+)$ {

      nchan_channel_id $1;
      nchan_authorize_request /subauth;
      nchan_websocket_ping_interval 30;
      nchan_subscriber websocket longpoll http-raw-stream;
      nchan_channel_group test;

    }

    location = /subauth {
 
      # 这里要换成自己的url
      proxy_pass http://182.92.152.61:8011/apis/subauth;
      proxy_set_header X-Subscriber-Type $nchan_subscriber_type;
      proxy_set_header X-Publisher-Type $nchan_publisher_type;
      proxy_set_header X-Message-Id $nchan_message_id;
      proxy_set_header X-Prev-Message-Id $nchan_prev_message_id;
      proxy_set_header X-Channel-Id $nchan_channel_id;

      proxy_set_header X-Original-URI $request_uri;

    }

  }
}
使用了基于 nginx 的一个插件[nchan]
服务器需要进行配置的优化,具体的可以参考请点击
 
5、运行
相关的配置文件我已经写在文档中, copy 保存成 nchan.conf
创建log目录 sudo mkdir /var/log/nginx
默认nginx 被安装到 /usr/local/nginx
运行 /usr/local/nginx/sbin/nginx -c path/to/nchan.conf

您可以选择一种方式赞助本站

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: