Nginx Detailed 28: NGINX Architecture Nginx + Lua Security WAF Firewall

Nginx+Lua’s secure waf firewall

Share pictures

Take a look at what others have written: https://github.com/loveshell/ngx_lua_waf

share picture

First install git: yum -y install git

share picture

Execute under /opt/download: git clone https://github.com/loveshell/ngx_lua_waf.git< /p>

Share a picture

If you can’t clone here, download it manually Then upload it to the server

share picture

Clone it down Move all the files under ngx_lua_waf to /etc/nginx/waf

Share pictures

Share a picture

Modify the Two paths

share picture

The file under wafconf is the interception rule for each location, which can be added and modified according to the actual situation

 Share picture

Integrate this lua script: add it to nginx.conf The following four lines of configuration

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

share picture

p>

share picture

Check the syntax , And reload
nginx -tc /etc/nginx/nginx.conf
nginx -s reload -c /etc/nginx/nginx.conf

share picture

Visit the previous SQL injection page, and inject SQL again, it is still successful. This is because there is no configuration in the firewall rules. This rule

share picture

< p>Add a new rule: \sor\s+

share picture

Restart nginx

share pictures

Injected SQL again and was blocked

share pictures

share picture

< p>Normal users can log in

share pictures

/p>

CCDeny of waf firewall: used to control the frequency of single IP access

share pictures

share picture

Restart nginx< /p>

share picture

Try to visit a matched one first URL, see if you can access it, if you can’t access it, see where it is mismatched

share picture

Run a concurrent session, and then visit the url, it will return 503, that is, it has been controlled by CCDeny

< img alt="Share a picture" src="/wp-content/uploads/images/opensource/nginx/1626813731841.png" >

Share a picture

Leave a Comment

Your email address will not be published.