17. Nginx and Lua development


Installing Lua and Lua for nginx

#Install Lua
yum install -y lua
lua -v

Installing a more efficient Lua interpreter luajit

wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
tar -zxvf LuaJIT-2.0.2.tar.gz
cd LuaJIT-2.0.2
make install PREFIX=/usr/local/LuaJIT/2.0.2
export LUAJIT_LIB=/usr/local/LuaJIT/2.0.2/lib
export LUAJIT_INC=/usr/local/LuaJIT/2.0.2/include/luajit-2.0
echo "/usr/local/LuaJIT/2.0.2/lib" >> /etc/ld.so.conf

Install NGX_ devel_ Kit and Lua nginx module

wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz
tar -zxvf v0.10.9rc7.tar.gz
tar -zxvf v0.3.0.tar.gz

#First make clean, then add a new module based on the original nginx. / configure
#If undefined reference to ` x509 appears_ check_ Host 'error, you need to add the -- with OpenSSL option to point to the directory where the source code of the OpenSSL 1.0.2 installation package is located.
./configure --add-module=/path/to/ngx_devel_kit-0.3.0 --add-module=/path/to/lua-nginx-module-0.10.9rc7
make && make install

Use nginx log to output request or response data


Nginx calls Lua

instructions explain
set_by_lua, set_by_lua_file Set nginx variable
access_by_llua, access_by_lua_file access control
content_by_lua, content_by_lua_file Receive request, output response

Lua calls nginx

variable explain
ngx.var Nginx variable
ngx.req.get_headers Get request header
ngx.req.get_uri_args Get request parameters
ngx.redirect redirect
ngx.print Output content
ngx.say with ngx.print , there will be one more line break
ngx.header Output response head

Thematic reading

  • 1. Advantages of nginx
  • 2. Installation and startup of nginx
  • 3. Nginx directory and configuration syntax
  • 4. Nginx module
  • 5. Nginx static resource processing
  • 6. Nginx browser cache principle
  • 7. Cross domain access of nginx resources
  • 8. Anti theft chain of nginx resources
  • 9. Nginx agent
  • 10. Nginx load balancing
  • 11. Nginx cache
  • 12. Nginx dynamic and static separation
  • 13. Nginx Rewrite
  • 14. Nginx Secure Link
  • 15. Nginx Geo
  • 16. Nginx HTTPS service
  • 17. Nginx and Lua development
  • 18. Nginx and Lua gray Publishing
  • 19. Nginx common errors
  • 20. Nginx performance optimization
  • 21. Nginx security management