OpenrestyLuanginx_upstream_check_module等其他模块安装

 

1.   软件

    LuaJIT

    LuaJIT-2.1.0-beta2.tar.gz

        

    Openresty 

Openresty-1.9.15.1.tar.gz

 

Nginx_upstream_check_module

nginx_upstream_check_module-master.zip

https://github.com/yaoweibin/nginx_upstream_check_module

NGINX后端服务负载均衡健康检查

 

nginx_http_push_module-master

nginx_http_push_module-master.zip

https://github.com/slact/nchan  https://nchan.io

实现服务器端的长连接和推送

 

ngx_python-master

ngx_python-master.zip

https://github.com/rryqszq4/ngx_python

NGINX中使用PYTHON语言

 

ngx_lua_waf-master

ngx_lua_waf-master.zip

https://github.com/loveshell/ngx_lua_waf?utm_source=tuicool&utm_medium=referral

基于lua-nginx-module(openresty)web应用防火墙

 

VeryNginx-master

VeryNginx-master.zip

https://github.com/alexazhou/VeryNginx#want-using-custom-nginx

提供NGINX 维护监控

 

其他第三方模块请参见

https://www.nginx.com/resources/wiki/modules/


其他依赖包

openssl-1.0.0e.tar.gz

pcre-8.10.tar.gz

zlib-1.2.5.tar.gz

 

安装软件时系统需要的支持包

gcc

gcc-c++

python2.7

python2.7-devel

 

2.  系统支持包检查和安装

        略

        

        

3.      安装

           将软件拷贝到目录(例如/tmp)下,并解压

                   目录结构如下:/tmp

                                 |-----LuaJIT-2.1.0-beta2

                                 |----- Openresty-1.9.15.1

                                 |----- nginx_upstream_check_module-master

                                 |----- nginx_http_push_module-master

                              |----- ngx_python-master

                              |----- ngx_lua_waf-master

                              |----- VeryNginx-master

                                 |----- openssl-1.0.0e

                                 |----- pcre-8.10

                                 |----- zlib-1.2.5

 

         ⑵  Luajit安装

Cd  /tmp/ LuaJIT-2.1.0-beta2

Make  &&  make install

 

⑶ 安装nginx_upstream_check_module模块

        Cd  nginx_upstream_check_module-master

        根据README中的提示进行安装

        Cd  /tmp/openresty-1.9.15.1/bundle/nginx-1.9.15

        patch -p1 < /tmp/nginx_upstream_check_module-master/check_1.9.2+.patch

                   如果报错可以试下

                   patch -p0 < /tmp/nginx_upstream_check_module-master/check_1.9.2+.patch

        如果NGINX版本是1.9.2及以上就使用check_1.9.2+.patch

                             

 wKiom1jZFVihZsqqAABkTKiAJ9s884.jpg-wh_50

 

    ⑶ 安装openresty到指定目录(/webapp/openresty)

        并安装附加模块:nginx_upstream_check_module-master

                        nginx_http_push_module-master

                        ngx_python-master

 

        Cd  /tmp/openresty-1.9.15.1/

 

        ./configure--prefix=/webapp/openresty   \

--with-http_stub_status_module  \

  --with-http_ssl_module \

  --with-http_addition_module \

 --with-http_realip_module \

 --with-http_flv_module \

 --with-http_gzip_static_module \

 --with-zlib=/tmp/zlib-1.2.5 \

 --with-pcre=/tmp/pcre-8.10  \

--with-openssl=/tmp/openssl-1.0.0e\

--add-module=/tmp/nginx_upstream_check_module-master\ #安装时指定模块

--add-module=/tmp/nginx_http_push_module-master \ #安装时指定模块

--add-module=/tmp/ngx_python-master\ #安装时指定模块

--user=webapp  --group=webapp

wKiom1jZFXTAOKBIAADIeyZqYto244.jpg-wh_50

gmake 

如果出现Python.h 文件不存在 的错误。

执行cp -R/usr/local/include/python2.7   /usr/include/

或者$export PYTHON_INC=/path/to/python/include/python2.7

$ export PYTHON_BIN=/path/to/python/bin

在重新configure,gmake

gmake  install

openresty安装完成

    ⑷ 验证

        Cd  /webapp/openresty/nginx/sbin

        ./nginx -V

wKioL1jZFZ_z_CEoAAEQA4cN-gY886.jpg-wh_50

 

⑸ 安装ngx_lua_waf-master模块

                   ngx_lua_waf-master里的文件拷贝到openrestynginx/conf/waf目录下

                   Mv  /tmp/ngx_lua_waf-master/*    /webapp/openresty/nginx/conf/waf

       nginx.confhttp段添加

            lua_package_path "/webapp/openresty/nginx/conf/waf/?.lua";

            lua_shared_dict limit 10m;

            init_by_lua_file  /webapp/openresty/nginx/conf/waf/init.lua;

            access_by_lua_file /webapp/openresty/nginx/conf/waf/waf.lua;

配置config.lua里的waf规则目录(一般在waf/conf/目录下)

            RulePath = "/webapp/openresty/nginx/conf/waf/wafconf/"

         

      当访问http://192.168.4.198/wwwroot.rar

      wKioL1jZFbPzgwdSAABKhjzytC4992.jpg-wh_50

 

 

⑹ 安装VeryNginx-master模块

        Cd   /tmp/VeryNginx-master

       python install.py install verynginx
         安装目录默认在   /opt/verynginx/
         Nginx.conf配置:
         ……
         include /opt/verynginx/verynginx/nginx_conf/in_external.conf;
         http {
             ……
             include /opt/verynginx/verynginx/nginx_conf/in_http_block.conf;
             server {
                    ……
                    include /opt/verynginx/verynginx/nginx_conf/in_server_block.conf;
                    }
             }
          访问  http://127.0.0.1/verynginx/index.html      User / Password: verynginx / verynginx
 

 

    ⑺  使用Ngx_python模块

        在NGINX.conf文件中添加

        

       wKiom1jZFfrxoy9pAABHpMj-Aac652.jpg-wh_50

 

 

    ⑻ 使用nginx_http_push_module-master模块

                   http://www.cnblogs.com/caosiyang/archive/2012/03/31/2426625.html

        Nginx.conf配置文件中添加

        location = /sub{

            set$push_channel_id $arg_id;

           push_subscriber;

           push_subscriber_concurrency broadcast;

           push_channel_group broadcast;

        }

 

        location= /pub {

            set$push_channel_id $arg_id;

           push_publisher;

           push_min_message_buffer_length 5;

            push_max_message_buffer_length 20;

           push_message_timeout 5s;

           push_channel_group broadcast;

        } 

   

启动Nginx,使用curl进行推送测试

1) subscriber请求数据:
curl -X GET localhost:8082/sub?id=1
向channel1请求数据,当前channel无数据,等待数据生成

2) publisher推送数据:
curl -X POST -d "data_to_push" localhost:8082/pub?id=1
向channel1推送数据,subscriber收到数据并返回