SlideShare a Scribd company logo
NGINX SCRIPTING
EXTENDING NGINX FUNCTIONALITIES WITH LUA
          Tony Fabeen / @tonyfabeen / SlimStacks
WHO AM I
NGINX ("ENGINE-X")
High performance HTTP, POP/IMAP and reverse proxy server.
Started in 2002 by Igor Sysoev, public in 2004.
Entirely written in C.
Hosts nearly 12.18% of active sites across all domains.
Nginx.com in 2011.
MASTER WORKER MODEL
$p ax|ge nix
        s u rp gn

ro 339..nix mse poes/p/gn/bnnix
 ot 12 . gn: atr rcs otnixsi/gn

ww 330..nix wre poes
 w 13 . gn: okr rcs
Nginx Scripting - Extending Nginx Functionalities with Lua
MASTER PROCESS
reading and validating configuration
creating, binding and closing sockets
starting, terminating and maintaining the configured number of w r e
                                                                okr
processes
re-opening log files
compiling embedded Perl scripts
WORKER PROCESS
Do all important stuff
Handle connection from clients
Reverse Proxy and Filtering functionalities
REQUEST PROCESSING
Nginx Scripting - Extending Nginx Functionalities with Lua
REQUEST PHASES
SERVER REWRITE PHASE
request URI transformation on virtual server level
FIND CONFIG PHASE
configuration location lookup
REWRITE PHASE
request URI transformation on location level
ACCESS PHASE
access restrictions check phase
TRY FILES PHASE
try_files directive processing phase
CONTENT PHASE
content generation phase
LOG PHASE
 logging phase
MODULARITY
Core Module
Functional Modules
CORE MODULE
Event Loop
Module execution control
FUNCTIONAL MODULES
Read from / Write to Network and Storage
Transform Content
Outbound Filtering
Server Side Includes
Upstream Server communication
...etc
LUA ON THE STAGE
A BIT OF LUA
 Created in Brazil
 Portable
 Simple
 Small
 Easy to embed
 Fast
OSS USING LUA
LUA NGINX MODULE
           https://github.com/chaoslawful/lua-nginx-module/
Created by TaoBao.com Engineers
High concurrent and non-blocking request processing
Programs can be written in the plain-old sequential way
Nginx takes care of I/O operations and Lua Nginx Module restore the
context and resume the program logic
LUA NGINX MODULE
         https://github.com/chaoslawful/lua-nginx-module
Introduces directives for running Lua inside Nginx
Exposes the Nginx environment to Lua via an Api
It's fast
Is even faster when compiled with LUA JIT(Just in Time Compiler)
NGINX LUA API
DIRECTIVES
Configuration directives serve as gateways to the Lua API within the
                           nginx.conf file.

     cnetb_u LASRP_TIG
     otn_yla U_CITSRN
     rwieb_u LASRP_TIG
     ert_yla U_CITSRN
     acs_ylaLASRP_TIG
     cesb_u U_CITSRN
     cnetb_u_iePT_OLASRP_IE
     otn_ylafl AHT_U_CITFL
     rwieb_u_iePT_OLASRP_IE
     ert_ylafl AHT_U_CITFL
     acs_ylafl PT_OLASRP_IE
     cesb_u_ie AHT_U_CITFL
      Unless you set l a c d _ a h to o f modules will be loaded once on the first request.
                      u_oecce f ,
NGX PACKAGE
Nginx Environment is exposed via n x
                                  g package
     nxagulag
      g.r.r_r
     nxvrVRAL_AE
      g.a.AIBENM
     nxhae.EDRATIUE
      g.edrHAE_TRBT
     nxcx
      g.t
HELLO WORLD !
  lcto /el-srb-u {
   oain hloue-yla
    dfuttp "etpan;
     eal_ye tx/li"
    cnetb_u '
     otn_yla
      nxsy"el," nxvragnm,""
       g.a(Hlo , g.a.r_ae !)
    ';
  }

  lcto /el-srb-gn {
   oain hloue-ynix
    eh "el,$r_ae!;
     co Hlo agnm "
  }

$cr ht:/oahs/el-srb-u?aeDvnap
  ul tp/lclothloue-ylanm=eISma
 Hlo Dvnap !
  el, eISma
$cr ht:/oahs/el-srb-gn?aeDvnap
  ul tp/lclothloue-ynixnm=eISma
 Hlo Dvnap !
  el, eISma
NGINX VARS
    lcto /csignixag {
     oain aesn-gn-rs
      st$is 3;
      e frt 5
      st$eod6;
      e scn 5

        stb_u $u '
         e_yla sm
          rtr nxvrfrt+nxvrscn
           eun g.a.is  g.a.eod
        ';

        eh "h smi $u"
        co Te u s sm;
    }

$cr ht:/oahs/csignixag
  ul tp/lclotaesn-gn-rs
 Tesmi 9
  h u s 9
NGINX SUBREQUESTS
lcto /u-urqet {
oain lasbeuss
 cnetb_u '
  otn_yla
  lclrsos =nxlcto.atr(/el-srb-gn?ae
   oa epne   g.oaincpue"hloue-ynixnm=
Dvnap"
eISma)
  i rsos.tts> 50te
   f epnesau = 0 hn
     nxei(epnesau)
     g.xtrsos.tts
  ed
   n

      nxsau =rsos.tts
       g.tts  epnesau
      nxsyrsos.oy
       g.a(epnebd)
    ';
}

$cr ht:/oahs/u-urqet
  ul tp/lclotlasbeuss
 Hlo Dvnap !
  el, eISma
NON BLOCKING I/O SUBREQUESTS
lcto /nltc-nrmn {
 oain aayisiceet
     cnetb_u '
      otn_yla
      lclrsos =nxlcto.atr(/ei"
       oa epne  g.oaincpue"rds,
          {rs={m ="nr,ky=nxvragln})
           ag  cd  ic" e  g.a.r_ik}
      nxsy"nrmne t :,nxvragln)
       g.a(Iceetd o " g.a.r_ik
     ';

}
lcto /ei {
 oain rds

    itra;
     nenl

    stuecp_r $e $r_e;
     e_nsaeui ky agky
    stuecp_r $m $r_m;
     e_nsaeui cd agcd

    rds_ur $m $e;
     ei2qey cd ky
    rds_as1700167;
     ei2ps 2...:39

}


$cr ht:/oahs/nltc-nrmn?ikht:/w.eismacmb
  ul tp/lclotaayisiceetln=tp/wwdvnap.o.r

    Iceetdt :tp/wwdvnap.o.r
     nrmne o ht:/w.eismacmb
FILTERS
HEADER FILTERS
lcto /{
 oain
  poyps ht:/oahs:00
   rx_as tp/lclot88;
  hae_itrb_u 'g.edrSre ="yLtl Sre";
   edrfle_yla nxhae.evr  M ite evr'
}

$cr - - HA ht:/oahs/edrfle
  ul i X ED tp/lclothae-itr
 HT/. 20O
  TP11 0 K
 Dt:Sn 0 Sp21 2:81 GT
  ae u, 9 e 02 11:1 M
 Sre:M Ltl Sre
  evr y ite evr
 CnetTp:tx/tlcastuf8
  otn-ye ethm;hre=t-
 CnetLnt:49
  otn-egh 4
 Cneto:ke-lv
  oncin epaie
 Sau:20O
  tts 0 K
 XFaeOtos smoii
  -rm-pin: aergn
 XXSPoeto:1 md=lc
  -S-rtcin ; oebok
 XCsae ps
  -acd: as
 XRc-ah:ms
  -akCce is
BODY FILTERS
lcto /oyfle {
oain bd-itr
 eh "ycnet;
  co M otn"

    bd_itrb_u '
     oyfle_yla
      nxag1 =srn.sbnxag1,"y,"or)
       g.r[]  tiggu(g.r[] M" Yu"
      nxag2 =tu -stefo ls canbfe
       g.r[]  re -e o r at hi ufr
    ';
}

$cr ht:/oahs/oyfle
  ul tp/lclotbd-itr
 Yu cnet
  or otn
COSOCKETS
Non Blocking, of course
Communicate via TCP or Unix domain sockets
Keepalive mechanism avoid connect/close for each request
COSOCKETS
lcto /ecce-rmla{
oain mmahdfo-u
 cnetb_u '
  otn_yla
  lclsc =nxsce.onc(17001,121
   oa ok  g.oktcnet"2..." 11)
  lclbts er=sc:ed"e fobrrn)
   oa ye, r  oksn(st o a"

     i ntbtste
      f o ye hn
       nxsy"aldt sn. " er
        g.a(fie o ed. n, r)
       rtr
        eun
     ed
      n

     lcldt =sc:eev(
      oa aa   okrcie)
     i ntdt te
      f o aa hn
       nxsy"aldt rciedt."
        g.a(Fie o eev aa.n)
     ed
      n

      nxsy"eut:" dt)
       g.a(Rsl  , aa
    ';

}
SOME LIBRARIES USING PURE COSOCKETS
    https://github.com/agentzh/lua-resty-memcached
    https://github.com/agentzh/lua-resty-redis
    https://github.com/agentzh/lua-resty-mysql
SUMMARY
The Nginx architecture is excellent for highly scalable applications.
Nginx can do a variety of things thanks to module extensions, and one can
resuse those extensions by issuing sub-requests in Lua.
lua-nginx-module makes use of the evented architecture in Nginx,
providing a powerful and performant programming environment.
It's possible to do 100% non-blocking I/O with readable code.
REFERENCES
http://www.aosabook.org/en/nginx.html
http://openresty.org
http://www.evanmiller.org/nginx-modules-guide.html
http://wiki.nginx.org/HttpLuaModule
BOOKS
QUESTIONS

   ?
THANKS
http://www.twitter.com/tonyfabeen

http://www.linkedin.com/in/tonyfabeen

https://github.com/tonyfabeen
Nginx Scripting - Extending Nginx Functionalities with Lua

More Related Content

What's hot (20)

PDF
Using ngx_lua in UPYUN 2
Cong Zhang
 
PDF
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher
 
PDF
Node.js streaming csv downloads proxy
Ismael Celis
 
PDF
Application Logging in the 21st century - 2014.key
Tim Bunce
 
KEY
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Tom Croucher
 
PDF
OWASP Proxy
Security B-Sides
 
PDF
Perl Memory Use 201209
Tim Bunce
 
PDF
Relayd: a load balancer for OpenBSD
Giovanni Bechis
 
PDF
Using ngx_lua in upyun 2
OpenRestyCon
 
PDF
tdc2012
Juan Lopes
 
PDF
Bootstrapping multidc observability stack
Bram Vogelaar
 
PPT
On UnQLite
charsbar
 
PDF
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
PDF
Pf: the OpenBSD packet filter
Giovanni Bechis
 
PDF
Новый InterSystems: open-source, митапы, хакатоны
Timur Safin
 
PDF
Tuning Solr for Logs
Sematext Group, Inc.
 
PDF
Node.js in production
Felix Geisendörfer
 
PDF
PL/Perl - New Features in PostgreSQL 9.0 201012
Tim Bunce
 
PDF
Top Node.js Metrics to Watch
Sematext Group, Inc.
 
ODP
Integrating icinga2 and the HashiCorp suite
Bram Vogelaar
 
Using ngx_lua in UPYUN 2
Cong Zhang
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher
 
Node.js streaming csv downloads proxy
Ismael Celis
 
Application Logging in the 21st century - 2014.key
Tim Bunce
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Tom Croucher
 
OWASP Proxy
Security B-Sides
 
Perl Memory Use 201209
Tim Bunce
 
Relayd: a load balancer for OpenBSD
Giovanni Bechis
 
Using ngx_lua in upyun 2
OpenRestyCon
 
tdc2012
Juan Lopes
 
Bootstrapping multidc observability stack
Bram Vogelaar
 
On UnQLite
charsbar
 
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
Pf: the OpenBSD packet filter
Giovanni Bechis
 
Новый InterSystems: open-source, митапы, хакатоны
Timur Safin
 
Tuning Solr for Logs
Sematext Group, Inc.
 
Node.js in production
Felix Geisendörfer
 
PL/Perl - New Features in PostgreSQL 9.0 201012
Tim Bunce
 
Top Node.js Metrics to Watch
Sematext Group, Inc.
 
Integrating icinga2 and the HashiCorp suite
Bram Vogelaar
 

Viewers also liked (20)

PDF
OAuth and OpenID Connect for Microservices
Twobo Technologies
 
PDF
Stateless authentication for microservices
Alvaro Sanchez-Mariscal
 
PDF
Nginx Internals
Joshua Zhu
 
PDF
Hacking Nginx at Taobao
Joshua Zhu
 
PDF
Nginx+lua在阿里巴巴的使用
OpenRestyCon
 
PPTX
Accelerating Nginx Web Server Performance
Bruce Tolley
 
PDF
Running PHP on Nginx / PHP wgtn
Harald Zeitlhofer
 
PPTX
Webpage Caches - the big picture (WordPress too)
Erich
 
PPTX
5 critical-optimizations.v2
Blaze Software Inc.
 
PPTX
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Jonathan Klein
 
ODP
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
PDF
基于OpenResty的百万级长连接推送
OpenRestyCon
 
PDF
High Performance Php My Sql Scaling Techniques
ZendCon
 
PDF
Nginx lua
Moriyoshi Koizumi
 
PPTX
Maximizing PHP Performance with NGINX
NGINX, Inc.
 
PDF
Practical ngx_mruby
Hiroshi SHIBATA
 
PDF
Nginx pres
James Fuller
 
PDF
Как и зачем создавать NginX-модуль - теория, практика, профит / Василий Сошни...
Ontico
 
PDF
Using ngx_lua / lua-nginx-module in pixiv
Shunsuke Michii
 
PDF
Devinsampa nginx-scripting
Tony Fabeen
 
OAuth and OpenID Connect for Microservices
Twobo Technologies
 
Stateless authentication for microservices
Alvaro Sanchez-Mariscal
 
Nginx Internals
Joshua Zhu
 
Hacking Nginx at Taobao
Joshua Zhu
 
Nginx+lua在阿里巴巴的使用
OpenRestyCon
 
Accelerating Nginx Web Server Performance
Bruce Tolley
 
Running PHP on Nginx / PHP wgtn
Harald Zeitlhofer
 
Webpage Caches - the big picture (WordPress too)
Erich
 
5 critical-optimizations.v2
Blaze Software Inc.
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Jonathan Klein
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Wim Godden
 
基于OpenResty的百万级长连接推送
OpenRestyCon
 
High Performance Php My Sql Scaling Techniques
ZendCon
 
Maximizing PHP Performance with NGINX
NGINX, Inc.
 
Practical ngx_mruby
Hiroshi SHIBATA
 
Nginx pres
James Fuller
 
Как и зачем создавать NginX-модуль - теория, практика, профит / Василий Сошни...
Ontico
 
Using ngx_lua / lua-nginx-module in pixiv
Shunsuke Michii
 
Devinsampa nginx-scripting
Tony Fabeen
 
Ad

Similar to Nginx Scripting - Extending Nginx Functionalities with Lua (20)

PDF
Socket programming, and openresty
Tavish Naruka
 
PDF
NginX - good practices, tips and advanced techniques
Claudio Borges
 
PPTX
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
NGINX, Inc.
 
PPTX
NGINX 101 - now with more Docker
sarahnovotny
 
PPTX
NGINX 101 - now with more Docker
Sarah Novotny
 
PDF
NGINX ADC: Basics and Best Practices – EMEA
NGINX, Inc.
 
KEY
Nginx - Tips and Tricks.
Harish S
 
PPTX
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX, Inc.
 
PDF
NGINX ADC: Basics and Best Practices
NGINX, Inc.
 
PPTX
NGINX: Basics and Best Practices
NGINX, Inc.
 
PDF
NGINX: Basics and Best Practices EMEA
NGINX, Inc.
 
PPTX
5 things you didn't know nginx could do
sarahnovotny
 
PPTX
Nginx
Geeta Vinnakota
 
PDF
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
Ortus Solutions, Corp
 
PPTX
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Amit Aggarwal
 
PDF
Nginx dhruba mandal
Dhrubaji Mandal ♛
 
PPTX
NGINX: Back to Basics – APCJ
NGINX, Inc.
 
PPTX
NGINX Installation and Tuning
NGINX, Inc.
 
PDF
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
PHP Conference Argentina
 
Socket programming, and openresty
Tavish Naruka
 
NginX - good practices, tips and advanced techniques
Claudio Borges
 
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
NGINX, Inc.
 
NGINX 101 - now with more Docker
sarahnovotny
 
NGINX 101 - now with more Docker
Sarah Novotny
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX, Inc.
 
Nginx - Tips and Tricks.
Harish S
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX, Inc.
 
NGINX ADC: Basics and Best Practices
NGINX, Inc.
 
NGINX: Basics and Best Practices
NGINX, Inc.
 
NGINX: Basics and Best Practices EMEA
NGINX, Inc.
 
5 things you didn't know nginx could do
sarahnovotny
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
Ortus Solutions, Corp
 
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
Amit Aggarwal
 
Nginx dhruba mandal
Dhrubaji Mandal ♛
 
NGINX: Back to Basics – APCJ
NGINX, Inc.
 
NGINX Installation and Tuning
NGINX, Inc.
 
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
PHP Conference Argentina
 
Ad

Recently uploaded (20)

PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
visibel.ai Company Profile – Real-Time AI Solution for CCTV
visibelaiproject
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PPTX
PCU Keynote at IEEE World Congress on Services 250710.pptx
Ramesh Jain
 
PDF
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
Market Wrap for 18th July 2025 by CIFDAQ
CIFDAQ
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PDF
SalesForce Managed Services Benefits (1).pdf
TechForce Services
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PDF
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
visibel.ai Company Profile – Real-Time AI Solution for CCTV
visibelaiproject
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PCU Keynote at IEEE World Congress on Services 250710.pptx
Ramesh Jain
 
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
Market Wrap for 18th July 2025 by CIFDAQ
CIFDAQ
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
SalesForce Managed Services Benefits (1).pdf
TechForce Services
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 

Nginx Scripting - Extending Nginx Functionalities with Lua

  • 1. NGINX SCRIPTING EXTENDING NGINX FUNCTIONALITIES WITH LUA Tony Fabeen / @tonyfabeen / SlimStacks
  • 3. NGINX ("ENGINE-X") High performance HTTP, POP/IMAP and reverse proxy server. Started in 2002 by Igor Sysoev, public in 2004. Entirely written in C. Hosts nearly 12.18% of active sites across all domains. Nginx.com in 2011.
  • 5. $p ax|ge nix s u rp gn ro 339..nix mse poes/p/gn/bnnix ot 12 . gn: atr rcs otnixsi/gn ww 330..nix wre poes w 13 . gn: okr rcs
  • 7. MASTER PROCESS reading and validating configuration creating, binding and closing sockets starting, terminating and maintaining the configured number of w r e okr processes re-opening log files compiling embedded Perl scripts
  • 8. WORKER PROCESS Do all important stuff Handle connection from clients Reverse Proxy and Filtering functionalities
  • 12. SERVER REWRITE PHASE request URI transformation on virtual server level
  • 14. REWRITE PHASE request URI transformation on location level
  • 16. TRY FILES PHASE try_files directive processing phase
  • 20. CORE MODULE Event Loop Module execution control
  • 21. FUNCTIONAL MODULES Read from / Write to Network and Storage Transform Content Outbound Filtering Server Side Includes Upstream Server communication ...etc
  • 22. LUA ON THE STAGE
  • 23. A BIT OF LUA Created in Brazil Portable Simple Small Easy to embed Fast
  • 25. LUA NGINX MODULE https://github.com/chaoslawful/lua-nginx-module/ Created by TaoBao.com Engineers High concurrent and non-blocking request processing Programs can be written in the plain-old sequential way Nginx takes care of I/O operations and Lua Nginx Module restore the context and resume the program logic
  • 26. LUA NGINX MODULE https://github.com/chaoslawful/lua-nginx-module Introduces directives for running Lua inside Nginx Exposes the Nginx environment to Lua via an Api It's fast Is even faster when compiled with LUA JIT(Just in Time Compiler)
  • 28. DIRECTIVES Configuration directives serve as gateways to the Lua API within the nginx.conf file. cnetb_u LASRP_TIG otn_yla U_CITSRN rwieb_u LASRP_TIG ert_yla U_CITSRN acs_ylaLASRP_TIG cesb_u U_CITSRN cnetb_u_iePT_OLASRP_IE otn_ylafl AHT_U_CITFL rwieb_u_iePT_OLASRP_IE ert_ylafl AHT_U_CITFL acs_ylafl PT_OLASRP_IE cesb_u_ie AHT_U_CITFL Unless you set l a c d _ a h to o f modules will be loaded once on the first request. u_oecce f ,
  • 29. NGX PACKAGE Nginx Environment is exposed via n x g package nxagulag g.r.r_r nxvrVRAL_AE g.a.AIBENM nxhae.EDRATIUE g.edrHAE_TRBT nxcx g.t
  • 30. HELLO WORLD ! lcto /el-srb-u { oain hloue-yla dfuttp "etpan; eal_ye tx/li" cnetb_u ' otn_yla nxsy"el," nxvragnm,"" g.a(Hlo , g.a.r_ae !) '; } lcto /el-srb-gn { oain hloue-ynix eh "el,$r_ae!; co Hlo agnm " } $cr ht:/oahs/el-srb-u?aeDvnap ul tp/lclothloue-ylanm=eISma Hlo Dvnap ! el, eISma $cr ht:/oahs/el-srb-gn?aeDvnap ul tp/lclothloue-ynixnm=eISma Hlo Dvnap ! el, eISma
  • 31. NGINX VARS lcto /csignixag { oain aesn-gn-rs st$is 3; e frt 5 st$eod6; e scn 5 stb_u $u ' e_yla sm rtr nxvrfrt+nxvrscn eun g.a.is g.a.eod '; eh "h smi $u" co Te u s sm; } $cr ht:/oahs/csignixag ul tp/lclotaesn-gn-rs Tesmi 9 h u s 9
  • 32. NGINX SUBREQUESTS lcto /u-urqet { oain lasbeuss cnetb_u ' otn_yla lclrsos =nxlcto.atr(/el-srb-gn?ae oa epne g.oaincpue"hloue-ynixnm= Dvnap" eISma) i rsos.tts> 50te f epnesau = 0 hn nxei(epnesau) g.xtrsos.tts ed n nxsau =rsos.tts g.tts epnesau nxsyrsos.oy g.a(epnebd) '; } $cr ht:/oahs/u-urqet ul tp/lclotlasbeuss Hlo Dvnap ! el, eISma
  • 33. NON BLOCKING I/O SUBREQUESTS lcto /nltc-nrmn { oain aayisiceet cnetb_u ' otn_yla lclrsos =nxlcto.atr(/ei" oa epne g.oaincpue"rds, {rs={m ="nr,ky=nxvragln}) ag cd ic" e g.a.r_ik} nxsy"nrmne t :,nxvragln) g.a(Iceetd o " g.a.r_ik '; } lcto /ei { oain rds itra; nenl stuecp_r $e $r_e; e_nsaeui ky agky stuecp_r $m $r_m; e_nsaeui cd agcd rds_ur $m $e; ei2qey cd ky rds_as1700167; ei2ps 2...:39 } $cr ht:/oahs/nltc-nrmn?ikht:/w.eismacmb ul tp/lclotaayisiceetln=tp/wwdvnap.o.r Iceetdt :tp/wwdvnap.o.r nrmne o ht:/w.eismacmb
  • 35. HEADER FILTERS lcto /{ oain poyps ht:/oahs:00 rx_as tp/lclot88; hae_itrb_u 'g.edrSre ="yLtl Sre"; edrfle_yla nxhae.evr M ite evr' } $cr - - HA ht:/oahs/edrfle ul i X ED tp/lclothae-itr HT/. 20O TP11 0 K Dt:Sn 0 Sp21 2:81 GT ae u, 9 e 02 11:1 M Sre:M Ltl Sre evr y ite evr CnetTp:tx/tlcastuf8 otn-ye ethm;hre=t- CnetLnt:49 otn-egh 4 Cneto:ke-lv oncin epaie Sau:20O tts 0 K XFaeOtos smoii -rm-pin: aergn XXSPoeto:1 md=lc -S-rtcin ; oebok XCsae ps -acd: as XRc-ah:ms -akCce is
  • 36. BODY FILTERS lcto /oyfle { oain bd-itr eh "ycnet; co M otn" bd_itrb_u ' oyfle_yla nxag1 =srn.sbnxag1,"y,"or) g.r[] tiggu(g.r[] M" Yu" nxag2 =tu -stefo ls canbfe g.r[] re -e o r at hi ufr '; } $cr ht:/oahs/oyfle ul tp/lclotbd-itr Yu cnet or otn
  • 37. COSOCKETS Non Blocking, of course Communicate via TCP or Unix domain sockets Keepalive mechanism avoid connect/close for each request
  • 38. COSOCKETS lcto /ecce-rmla{ oain mmahdfo-u cnetb_u ' otn_yla lclsc =nxsce.onc(17001,121 oa ok g.oktcnet"2..." 11) lclbts er=sc:ed"e fobrrn) oa ye, r oksn(st o a" i ntbtste f o ye hn nxsy"aldt sn. " er g.a(fie o ed. n, r) rtr eun ed n lcldt =sc:eev( oa aa okrcie) i ntdt te f o aa hn nxsy"aldt rciedt." g.a(Fie o eev aa.n) ed n nxsy"eut:" dt) g.a(Rsl , aa '; }
  • 39. SOME LIBRARIES USING PURE COSOCKETS https://github.com/agentzh/lua-resty-memcached https://github.com/agentzh/lua-resty-redis https://github.com/agentzh/lua-resty-mysql
  • 40. SUMMARY The Nginx architecture is excellent for highly scalable applications. Nginx can do a variety of things thanks to module extensions, and one can resuse those extensions by issuing sub-requests in Lua. lua-nginx-module makes use of the evented architecture in Nginx, providing a powerful and performant programming environment. It's possible to do 100% non-blocking I/O with readable code.
  • 42. BOOKS
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy