Home Backend Development PHP Tutorial Security foundation of nginx (nginx+waf+lua)

Security foundation of nginx (nginx+waf+lua)

Jul 29, 2016 am 09:15 AM
module nbsp nginx usr

Thanks to the great people on the Internet for providing the documentation.

nginx waf +lua security module construction , web application firewall on nginx

Required software:

1. LuaJIT download website: http://luajit.org (current stable version: 2.0.4 )
2, ngx_devel_kit-0.2.19.tar
3, lua-nginx-module-0.9.5rc2.tar
4, master.zip
5, nginx
optimize nginx package
1, libunwind
2, gperftools

1. Install LuaJIT

tar -zxvf LuaJIT.tar.gz

make

make install

After installation, lib, include Place directly in /usr/local/lib and /usr/local/include

2. Unzip ngx_devel_kit, lua-nginx-module

3. Set environment variables

export LUAJIT_LIB=/usr /local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH

4. Install nginx (version 1.6.1 , failed in 1.9.4)

4.1 optimized nginx

vim /usr/local/src/nginx-1.6.1/auto/cc/gcc

Comments: #debug
#CFLAGS ="$CFLAGS -g"

Explanation: Turn off the nginx debug module and reduce the size of the nginx installation package

4.2 Optimize nginx

Explanation: Optimize nginx performance, improve memory allocationefficiency and speed a lot, Reduce load. Need to install libunwind and gperftools

4.2.1 Install libunwind

tar -xf /usr/local/src/libunwind.tar.gz

cd /usr/local/src/libunwind
CFLA GS =-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

4.2.2 Install gperftools

tar -xf /usr/local/src/gperftools.tar.gz
cd / usr/local/src/gperftools
make && make install

mkdir /tmp/tcmalloc //Create a tcmalloc thread to write the file
777 echo "/usr/local /lib" >/etc/ld.so.conf.d/usr_local_lib.conf #Enable the configuration of google_perftools_profiles in nginx.conf to take effect

4.2.3 Install nginx

cd /usr/local/src/ nginx-1.6.1/

For example: Production environment: Note that the paths of ngx_devel_kit-0.2.19 and lua-nginx-module-0.9.5rc2 must be correct--prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module --add-module=/usr/local/nginx_upstream_check_module-master --with-http_stub_status_module --add- module=/usr/local/src/ngx_devel_kit-0.2.19 --add-module=/usr/local/src/lua-nginx-module-0.9.5rc2 --with-google_perftools_module

make && make install

4.2.4 adds ngx_lua_waf_master

unzip -o /usr /local/src/ngx_lua_waf_master.zip mv /usr/local/src/ngx_lua_waf_master /usr/local/nginx/conf/waf


#Create a folder to store waf logs, which requires write permission
mkidr /home /nignx_waf_log/

chmod 777 /home/nginx_waf_log/

vim /usr/local/src/nginx/conf/waf/conf.lua


RulePath = "/ usr/local/nginx-help /conf/waf/wafconf/" #Specify the waf rule storage folder
logdir = "/home/nginx_waf_log" #Specify the waf log storage location
vim /usr/local/nginx/conf/nginx.conf #Add under pid, support gperftools library

google_perftools_profiles /tmp/tcmalloc/tcmalloc.;

#Add under http lua_package_path "/usr/local/nginx/conf/waf/?.lua";
dict lua_shared_ limit 10m;
init_by_lua_file /usr/local/nginx/conf/waf/init.lua;
access_by_lua_file /usr/local/nginx/conf/waf/waf.lua;



Then start nginx

and add the website sub-connection url? id=../etc/passwd; Check whether the firewall blocking page will appear
lsof -n | greo tcmalloc Check whether gperftools is running normally

In official use, use the one provided on www.wooyun.org waf module, the rules can be modified according to your needs

The above introduces the security foundation of nginx (nginx+waf+lua), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

See all articles