2014-03-02 09:38:01
来 源
kejihao
Nginx
本文介绍Nginx和Nginx_http_push_module模块安装和设置方法,希望对于初学Nginx服务器相关的朋友有帮助,更多Nginx安装、配置、报错处理等资源请本站内搜索。。

一.   Nginx和nginx_http_push_module模块安装及部署:

1.

到http://nginx.org/en/download.html 下载nginx-0.8.53.tar.gz

到 http://pushmodule.slact.net/#download 下载 nginx_http_push_module模块

到 http://www.pcre.org/下载pcre(正则表达式) 函数库源代码

2.       上传到”/home/你的用户名”目录中,并解压缩:

tar -zxvf nginx-0.8.53.tar.gz.

tar -zxvf nginx_http_push_module-0.692.tar.gz

tar –zxvf pcre-8.10.tar.gz

3.若你的linux中没有安装C编辑器gcc和C++编辑器g++,则用以下命令安装:

sudo apt-get install gcc

sudo apt-get install g++

若已安装,则跳过该步骤.

4.需要安装2个C函数库:

4.1 pcre(正则表达式) ,编译安装:

./configure

make

sudo make install

4.2 SSL: apt-get install libssl-dev

5.解压后,进入/home/你的用户名/nginx-0.8.53目录

6.安装Nginx:

./configure  –add-module=../nginx_http_push_module-0.692 –with-cc-opt=’-O2′

7. 编译Nginx:

make

8.编译安装:

sudo make install

二.   安装php和mysql:

sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql

三.   FastCgi/php5-fpm(二选一):

1.  安装FastCgi :

sudo apt-get install spawn-fcgi

启动:

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi

2.       安装php5-fpm:

1)       下载:

sudo apt-get install php5-fpm

2)       修改/etc/php5/fpm/pool.d/www.conf中的pm.max_children=50 和request_terminate_timeout = 1200

3)       启动php-fpm:

/etc/init.d/php5-fpm start

 

四.   修改nginx_http_push模块的配置和测试:

1.       修改nginx.conf:

1.1   worker_processes  10;

1.2   event部分加入  use epoll;

1.3   http部分加入:

fastcgi_connect_timeout 1200;

fastcgi_send_timeout 1200;

fastcgi_read_timeout 1200;

fastcgi_buffer_size 128k;

fastcgi_buffers 8 128k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

push_max_reserved_memory 10M;

并修改 keepalive_timeout  615;

1.4  server部分加入:

location /Microsoft-Server-ActiveSync {

root html;

if ($args ~ Cmd=Ping){

rewrite /Microsoft-Server-ActiveSync /activity last;

}

rewrite /Microsoft-Server-ActiveSync /z-push/index.php last;

}

location /publish {

set $push_channel_id $arg_user; #/?id=239aff3 or somesuch

push_publisher;

push_store_messages on; # enable message queueing

push_message_timeout 2h; # expire buffered messages after 2 hours

push_max_message_buffer_length 10; # store 10 messages

#push_min_message_recipients 0; # minimum recipients before purge

}

# public long-polling endpoint

location /activity {

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_user;

default_type text/plain;

}

2         启动nginx:

/usr/local/nginx/sbin/nginx

3         测试:

4         地址栏中输入http://localhost/Microsoft-Server-ActiveSync?Cmd=Ping&user=osa

5         浏览器会处于等待状态,等待Ping返回一个值

6         在linux的命令行中输入 telnet 127.0.0.1 80

7         并输入测试

8         POST /publish?user=osa HTTP/1.0

8Content-Length: 1

a

(以上为一段完整测试代码)

9         测试结果:浏览器会呈现一个字符a,即测试成功

10       停止Nginx:

11       /usr/local/nginx/sbin/nginx –s stop

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。