Benjamin Zhang

目前就职于中科院计算机网络信息中心,主要兴趣集中在数据库,操作系统,中间件。

【Nginx】tengine部署安装

26 Feb 2019 » Nginx

tengine部署安装

  1. 安装部署(前置基础)

    yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel -y
    
  2. LuaJIT编译安装

    [root@pingCSTNET ~]# wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
    [root@pingCSTNET ~]# tar zxvf LuaJIT-2.0.5.tar.gz 
    [root@pingCSTNET ~]# cd LuaJIT-2.0.5
    [root@pingCSTNET ~]# make
    [root@pingCSTNET ~]# make install PREFIX=/usr/local/luajit
    
  3. tengine编译安装

    wget http://tengine.taobao.org/download/tengine-2.2.3.tar.gz
    tar zxvf tengine-2.2.3.tar.gz
    cd tengine-2.2.3
    ./configure --prefix=/opt/nginx --with-http_lua_module --with-luajit-lib=/usr/local/luajit/lib/ --with-luajit-inc=/usr/local/luajit/include/luajit-2.0/ --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib
    make && make install
    
  4. ngx_lua_waf安装

    cd /opt
    [root@pingCSTNET opt]# wget https://github.com/loveshell/ngx_lua_waf/archive/master.zip
    [root@pingCSTNET opt]# unzip master.zip
    [root@pingCSTNET opt]# mv ngx_lua_waf-master /opt/nginx/conf/
    [root@pingCSTNET opt]# cd /opt/nginx/conf/ 
    [root@pingCSTNET conf]# mv ngx_lua_waf-master  waf
    
  5. ngx_lua_waf配置

    [root@pingCSTNET ~]# vi /opt/nginx/conf/waf/config.lua
    把前三行修改如下:
    RulePath = "/opt/nginx/conf/waf/wafconf/"
    attacklog = "on"
    logdir = "/opt/nginx/logs/waf"
    

    端,添加如下内容:

    lua_package_path "/opt/nginx/conf/waf/?.lua";
    lua_shared_dict limit 10m;
    init_by_lua_file  /opt/nginx/conf/waf/init.lua; 
    access_by_lua_file /opt/nginx/conf/waf/waf.lua;
    limit_req_zone $binary_remote_addr $uri zone=limit_uri:3m rate=100r/s;
    

    端,添加如下内容:

        location @limitpage {
            rewrite ^ /test1.html;
        }
        和在"localtion /"下添加:
         limit_req zone=limit_uri burst=1 forbid_action=@limitpage;
    

    进入nginx目录/html,具体路径为:/opt/nginx/html

    [root@pingCSTNET html]# cd /opt/nginx/html/
    [root@pingCSTNET html]# ls
    50x.html  index.html
    [root@pingCSTNET html]# vi 503.html
    <html>
    <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Error</title>
            <style>
                    .container{width:50%; margin:5% auto; background:#f5f5f5; padding:2em; border-radius:4px; border:1px solid #ccc; text-align:center;}
            </style>
    </head>
    <body class="dHome-body gray">
            <div class="container">
                    <h1>您的访问过于频繁,请稍后重试。</h1>
            </div>
    </body>
    </html>
    

Related Posts