完整参数附录:
./configure --prefix=http://www.likecs.com/etc/nginx --sbin-path=http://www.likecs.com/usr/sbin/nginx --modules-path=http://www.likecs.com/usr/lib64/nginx/modules --conf-path=http://www.likecs.com/etc/nginx/nginx.conf --error-log-path=http://www.likecs.com/var/log/nginx/error.log --http-log-path=http://www.likecs.com/var/log/nginx/access.log --pid-path=http://www.likecs.com/var/run/nginx.pid --lock-path=http://www.likecs.com/var/run/nginx.lock --http-client-body-temp-path=http://www.likecs.com/var/cache/nginx/client_temp --http-proxy-temp-path=http://www.likecs.com/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=http://www.likecs.com/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=http://www.likecs.com/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=http://www.likecs.com/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=../ngx_devel_kit-0.3.1 --add-module=../lua-nginx-module-0.10.15 3.3.3.重新编译安装nginx编译安装:make && make install
3.3.4.共享lua动态库加载lua库到ld.so.conf文件
echo "/usr/local/LuaJIT/lib" >> /etc/ld.so.conf
执行ldconfig让动态函式库加载到缓存中
3.3.5.验证Lua模块验证下Lua是否已经可用:
在nginx.config的server节点下添加:
PS:vi /etc/nginx/nginx.conf
server { listen 80; server_name localhost; charset utf-8; # 默认编码为utf-8 location / { root html; index index.html index.htm; } ... # 测试Nginx的Lua(添加这一段) location /hello { default_type 'text/plain'; content_by_lua 'ngx.say("欢迎访问逸鹏说道公众号~")'; } ... }检查配置:nginx -t -c /etc/nginx/nginx.conf
PS:配置生效:nginx -s reload -c /etc/nginx/nginx.conf
看看效果:
扩展:你可以试试获取ip哦~
# 获取客户端ip location /myip { default_type 'text/plain'; content_by_lua ' clientIP = ngx.req.get_headers()["x_forwarded_for"] ngx.say("IP:",clientIP) '; } 4.Nginx+Lua搭建WAF防火墙市面上比较常用一块开源项目:ngx_lua_waf
https://github.com/loveshell/ngx_lua_waf
拦截Cookie类型工具
拦截异常post请求
拦截CC洪水攻击
拦截URL
拦截arg(提交的参数)