centos5.2 源码安装nginx+php-fpm+http push,演示http push 功能,测试通过

参照solo的
http://cn.astercc.org/2010/12/29/centos%E4%B8%8B%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AEnginxhttp-pushapcphp-fpm.html
参照杜威的
http://blog.duwei.name/?p=166


第一部分:源码安装nginx+php-fpm+http push

步骤如下


1:安装php-fpm

yum remove php-cli php-common php
cd /usr/src
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/epel-release-5-4.noarch.rpm
wget  http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-8.ius.el5.noarch.rpm
rpm -Uvh epel-release-5-4.noarch.rpm ius-release-1.0-8.ius.el5.noarch.rpm
vi /etc/yum.repos.d/ius.repo
注释掉下面一行
mirrorlist=http://dmirr.iuscommunity.org/mirrorlist?repo=ius-el5&arch=$basearch
增加这一行
baseurl=http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/$basearch


yum install php53u-fpm php53u-pecl-apc php53u-mysql


chkconfig php-fpm on


2:安装nginx和http push安装完毕



wget http://www.nginx.org/download/nginx-0.8.54.tar.gz
wget http://pushmodule.slact.net/downloads/nginx_http_push_module-0.692.tar.gz
tar zxf nginx-0.8.54.tar.gz
tar zxf nginx_http_push_module-0.692.tar.gz
cd nginx-0.8.54
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_gzip_static_module --add-module=/usr/src/nginx_http_push_module-0.692
make
make install




第二部:配置nginx+php-fpm+http push

1:php-fpm

不用怎么修改,按照默认的即可(此处没有按照solo的做)


2:nginx

vi /usr/local/nginx/conf/nginx.conf  如下


user www www; 


#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
error_log  /www/logs/nginx_error.log  crit;  
#pid        logs/nginx.pid;
pid /www/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;


    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  /www/logs/access.log  main;


    sendfile        on;
    #tcp_nopush     on;


    #keepalive_timeout  0;
    keepalive_timeout  65;


    #gzip  on;


    server {
        listen       80;
        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {
            root  /www/wwwroot/; 
            index  index.html index.htm;
            push_channel_group pushmodule_comet;
 
                        location /pub {
                            set $push_channel_id comet;
                            push_publisher;
                            push_message_timeout 5s;        # Give the clients time
                            push_min_message_buffer_length 5;
                            push_max_message_buffer_length 20;
                        }       
                 
                        location /sub {
                            default_type  text/json;
                            set $push_channel_id comet;
                            push_subscriber;
                            send_timeout 3600;
                        }  
        }


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root  /www/wwwroot/; 
        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ .*\.(php|php5)?$
        {
                root  /www/wwwroot/; 
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index  index.php;  
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_connect_timeout 60;
                fastcgi_send_timeout 180;
                fastcgi_read_timeout 180;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
                fastcgi_intercept_errors on;
        }


        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
        
    }




    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;


    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}




    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;


    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;


    #    ssl_session_timeout  5m;


    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;


    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


}






3:配置nginx开机启动



vi /etc/init.d/nginx


#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid


# Source function library.
. /etc/rc.d/init.d/functions


# Source networking configuration.
. /etc/sysconfig/network


# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0


nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)


NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"


[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx


lockfile=/var/lock/subsys/nginx


start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}


stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}


restart() {
    configtest || return $?
    stop
    start
}


reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}


force_reload() {
    restart
}


configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}


rh_status() {
    status $prog
}


rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
   ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac






chmod +x /etc/init.d/nginx
chkconfig nginx on




4:启动服务



service nginx start
service php-fpm start




第三部:测试http push



把 send.html 和listen.html 传到 /www/wwwroot/目录下
把 run.php 传到服务器任意目录下


访问http://192.168.1.62/listen.html 和 http://192.168.1.62/send.html


试试发送数据,呵呵,挺好玩的
另外再运行 php run.php

看看效果吧


本文中涉及到的源码和文件下载

http://download.youkuaiyun.com/source/3481713

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值