Linux下給nginx安裝waf模組_nginx

來源:互聯網
上載者:User

最近上新項目,搭建nginx的時候為保證安全,決定安裝下waf模組,以下是具體步驟,首先下載需要的安裝包,進行每個安裝:

wget http://luajit.org/download/LuaJIT-2.0.3.tar.gztar -zxvf LuaJIT-2.0.3.tar.gzcd LuaJIT-2.0.3makemake install

然後下載nginx,

wget http://nginx.org/download/nginx-1.7.6.tar.gztar -zxvf nginx-1.7.6.tar.gz

下載ngx_devel_kit,

wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz –no-check-certificatetar -zxvf v0.2.19.tar.gz

下載nginx_lua_module

wget https://github.com/openresty/lua-nginx-module/archive/v0.9.13rc1.tar.gz –no-check-certificatetar -zxvf v0.9.13rc1.tar.gzcd nginx-1.7.6

安裝pcre,

tar -zxvf pcre-8.30.tar.gzcd pcre-8.30./configuremakemake install

安裝openssl,

tar -zxvf openssl-1.0.0.tar.gz

安裝ngx_cache_purge模組:

tar   -zxvf  ngx_cache_purge-1.3.tar.gz

安裝zlib,    yum install zlib zlib-devel

設定環境變數,進行編譯,

export LUAJIT_LIB=/usr/local/libexport LUAJIT_INC=/usr/local/include/luajit-2.0./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –add-module=/root/ngx_devel_kit-0.2.19 –add-module=/root/lua-nginx-module-0.9.13rc1 –with-http_ssl_module –with-openssl=/root/openssl-1.0.0 –add-module=/root/ngx_cache_purge-1.3 –with-pcre=/root/pcre-8.30 –with-ld-opt=”-Wl,-rpath,$LUAJIT_LIB”make -j2make install

建立目錄存放攻擊日誌:

mkdir -p /data/logs/hack/chown -R nobody:nobody /data/logs/hack/chmod -R 755 /data/logs/hack/

下載waf,

wget https://github.com/loveshell/ngx_lua_waf/archive/master.zip –no-check-certificateunzip master.zipcd ngx_lua_waf-master/mkdir /usr/local/nginx/conf/wafmv * /usr/local/nginx/conf/waf/cd /usr/local/nginx/conf/vi nginx.conf

在http 段加入:

lua_package_path “/usr/local/nginx/conf/waf/?.lua”;
lua_shared_dict limit 10m;
init_by_lua_file  /usr/local/nginx/conf/waf/init.lua;
access_by_lua_file /usr/local/nginx/conf/waf/waf.lua;

啟動前運行: ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2  否則會找不到這個模組報錯。

過濾規則在wafconf下,可根據需求自行調整,每條規則需換行,或者用|分割
global是全域過濾檔案,裡面的規則對post和get都過濾
get是只在get請求過濾的規則
post是只在post請求過濾的規則
whitelist是白名單,裡面的url匹配到不做過濾
user-agent是對user-agent的過濾規則

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.