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
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
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
Devinsampa nginx-scripting

More Related Content

What's hot

Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with PerlKazuho Oku
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X ServerYasuhiro Asaka
 
Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD
Giovanni Bechis
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
rjsmelo
 
node.js workshop- node.js basics
node.js workshop- node.js basicsnode.js workshop- node.js basics
node.js workshop- node.js basicsQiong Wu
 
node.js workshop- node.js middleware
node.js workshop- node.js middlewarenode.js workshop- node.js middleware
node.js workshop- node.js middlewareQiong Wu
 
agri inventory - nouka data collector / yaoya data convertor
agri inventory - nouka data collector / yaoya data convertoragri inventory - nouka data collector / yaoya data convertor
agri inventory - nouka data collector / yaoya data convertor
Toshiaki Baba
 
Ssh cookbook
Ssh cookbookSsh cookbook
Ssh cookbook
Jean-Marie Renouard
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony componentsMichael Peacock
 
nouka inventry manager
nouka inventry managernouka inventry manager
nouka inventry manager
Toshiaki Baba
 
OWASP Proxy
OWASP ProxyOWASP Proxy
OWASP Proxy
Security B-Sides
 
Scaling antispam solutions with Puppet
Scaling antispam solutions with PuppetScaling antispam solutions with Puppet
Scaling antispam solutions with Puppet
Giovanni Bechis
 
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
trexy
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
Kirk Kimmel
 
Clone database using_active_duplicate
Clone database using_active_duplicateClone database using_active_duplicate
Clone database using_active_duplicateViaggio Italia
 
Put on Your Asynchronous Hat and Node
Put on Your Asynchronous Hat and NodePut on Your Asynchronous Hat and Node
Put on Your Asynchronous Hat and Node
Marc Fasel
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
Ian Barber
 
How to recognise that the user has just uninstalled your android app droidc...
How to recognise that the user has just uninstalled your android app   droidc...How to recognise that the user has just uninstalled your android app   droidc...
How to recognise that the user has just uninstalled your android app droidc...Przemek Jakubczyk
 
How to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android appHow to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android app
Przemek Jakubczyk
 
ES6 generators
ES6 generatorsES6 generators
ES6 generators
Steven Foote
 

What's hot (20)

Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with Perl
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
 
Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
node.js workshop- node.js basics
node.js workshop- node.js basicsnode.js workshop- node.js basics
node.js workshop- node.js basics
 
node.js workshop- node.js middleware
node.js workshop- node.js middlewarenode.js workshop- node.js middleware
node.js workshop- node.js middleware
 
agri inventory - nouka data collector / yaoya data convertor
agri inventory - nouka data collector / yaoya data convertoragri inventory - nouka data collector / yaoya data convertor
agri inventory - nouka data collector / yaoya data convertor
 
Ssh cookbook
Ssh cookbookSsh cookbook
Ssh cookbook
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony components
 
nouka inventry manager
nouka inventry managernouka inventry manager
nouka inventry manager
 
OWASP Proxy
OWASP ProxyOWASP Proxy
OWASP Proxy
 
Scaling antispam solutions with Puppet
Scaling antispam solutions with PuppetScaling antispam solutions with Puppet
Scaling antispam solutions with Puppet
 
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
Clone database using_active_duplicate
Clone database using_active_duplicateClone database using_active_duplicate
Clone database using_active_duplicate
 
Put on Your Asynchronous Hat and Node
Put on Your Asynchronous Hat and NodePut on Your Asynchronous Hat and Node
Put on Your Asynchronous Hat and Node
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
How to recognise that the user has just uninstalled your android app droidc...
How to recognise that the user has just uninstalled your android app   droidc...How to recognise that the user has just uninstalled your android app   droidc...
How to recognise that the user has just uninstalled your android app droidc...
 
How to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android appHow to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android app
 
ES6 generators
ES6 generatorsES6 generators
ES6 generators
 

Viewers also liked

Architecture and implementation of Apache Lucene
Architecture and implementation of Apache LuceneArchitecture and implementation of Apache Lucene
Architecture and implementation of Apache Lucene
Josiane Gamgo
 
Search Lucene
Search LuceneSearch Lucene
Search Lucene
Jeremy Coates
 
Introduction To Apache Lucene
Introduction To Apache LuceneIntroduction To Apache Lucene
Introduction To Apache Lucene
Mindfire Solutions
 
Solr
SolrSolr
Solr
sortivo
 
Munching & crunching - Lucene index post-processing
Munching & crunching - Lucene index post-processingMunching & crunching - Lucene index post-processing
Munching & crunching - Lucene index post-processing
abial
 
Text Indexing / Inverted Indices
Text Indexing / Inverted IndicesText Indexing / Inverted Indices
Text Indexing / Inverted Indices
Carlos Castillo (ChaTo)
 
From Lucene to Elasticsearch, a short explanation of horizontal scalability
From Lucene to Elasticsearch, a short explanation of horizontal scalabilityFrom Lucene to Elasticsearch, a short explanation of horizontal scalability
From Lucene to Elasticsearch, a short explanation of horizontal scalability
Stéphane Gamard
 
Nginx-lua
Nginx-luaNginx-lua
Lucene
LuceneLucene
Lucene
Matt Wood
 
Lucene and MySQL
Lucene and MySQLLucene and MySQL
Lucene and MySQL
farhan "Frank"​ mashraqi
 
Nginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with LuaNginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with LuaTony Fabeen
 
Lucandra
LucandraLucandra
Lucandra
otisg
 
Inverted index
Inverted indexInverted index
Inverted index
Krishna Gehlot
 
Intelligent crawling and indexing using lucene
Intelligent crawling and indexing using luceneIntelligent crawling and indexing using lucene
Intelligent crawling and indexing using luceneSwapnil & Patil
 
An introduction to inverted index
An introduction to inverted indexAn introduction to inverted index
An introduction to inverted indexweedge
 
Apache Solr/Lucene Internals by Anatoliy Sokolenko
Apache Solr/Lucene Internals  by Anatoliy SokolenkoApache Solr/Lucene Internals  by Anatoliy Sokolenko
Apache Solr/Lucene Internals by Anatoliy Sokolenko
Provectus
 
Berlin Buzzwords 2013 - How does lucene store your data?
Berlin Buzzwords 2013 - How does lucene store your data?Berlin Buzzwords 2013 - How does lucene store your data?
Berlin Buzzwords 2013 - How does lucene store your data?
Adrien Grand
 
Introduction to solr
Introduction to solrIntroduction to solr
Introduction to solr
Sematext Group, Inc.
 

Viewers also liked (20)

Nginx lua
Nginx luaNginx lua
Nginx lua
 
Architecture and implementation of Apache Lucene
Architecture and implementation of Apache LuceneArchitecture and implementation of Apache Lucene
Architecture and implementation of Apache Lucene
 
Search Lucene
Search LuceneSearch Lucene
Search Lucene
 
Introduction To Apache Lucene
Introduction To Apache LuceneIntroduction To Apache Lucene
Introduction To Apache Lucene
 
Solr
SolrSolr
Solr
 
Munching & crunching - Lucene index post-processing
Munching & crunching - Lucene index post-processingMunching & crunching - Lucene index post-processing
Munching & crunching - Lucene index post-processing
 
Index types
Index typesIndex types
Index types
 
Text Indexing / Inverted Indices
Text Indexing / Inverted IndicesText Indexing / Inverted Indices
Text Indexing / Inverted Indices
 
From Lucene to Elasticsearch, a short explanation of horizontal scalability
From Lucene to Elasticsearch, a short explanation of horizontal scalabilityFrom Lucene to Elasticsearch, a short explanation of horizontal scalability
From Lucene to Elasticsearch, a short explanation of horizontal scalability
 
Nginx-lua
Nginx-luaNginx-lua
Nginx-lua
 
Lucene
LuceneLucene
Lucene
 
Lucene and MySQL
Lucene and MySQLLucene and MySQL
Lucene and MySQL
 
Nginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with LuaNginx Scripting - Extending Nginx Functionalities with Lua
Nginx Scripting - Extending Nginx Functionalities with Lua
 
Lucandra
LucandraLucandra
Lucandra
 
Inverted index
Inverted indexInverted index
Inverted index
 
Intelligent crawling and indexing using lucene
Intelligent crawling and indexing using luceneIntelligent crawling and indexing using lucene
Intelligent crawling and indexing using lucene
 
An introduction to inverted index
An introduction to inverted indexAn introduction to inverted index
An introduction to inverted index
 
Apache Solr/Lucene Internals by Anatoliy Sokolenko
Apache Solr/Lucene Internals  by Anatoliy SokolenkoApache Solr/Lucene Internals  by Anatoliy Sokolenko
Apache Solr/Lucene Internals by Anatoliy Sokolenko
 
Berlin Buzzwords 2013 - How does lucene store your data?
Berlin Buzzwords 2013 - How does lucene store your data?Berlin Buzzwords 2013 - How does lucene store your data?
Berlin Buzzwords 2013 - How does lucene store your data?
 
Introduction to solr
Introduction to solrIntroduction to solr
Introduction to solr
 

Similar to Devinsampa nginx-scripting

Noah Zoschke at Waza 2013: Heroku Secrets
Noah Zoschke at Waza 2013: Heroku SecretsNoah Zoschke at Waza 2013: Heroku Secrets
Noah Zoschke at Waza 2013: Heroku Secrets
Heroku
 
Beginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at GoogleBeginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at Google
Ari Lerner
 
Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Odoo
 
Marko Gargenta_Remixing android
Marko Gargenta_Remixing androidMarko Gargenta_Remixing android
Marko Gargenta_Remixing androidDroidcon Berlin
 
linux-namespaces.pdf
linux-namespaces.pdflinux-namespaces.pdf
linux-namespaces.pdf
Ignat Korchagin
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
Command Prompt., Inc
 
Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.
Prajal Kulkarni
 
Keep it simple web development stack
Keep it simple web development stackKeep it simple web development stack
Keep it simple web development stack
Eric Ahn
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleMattias Gees
 
An Introduction to CSS Preprocessors
An Introduction to CSS PreprocessorsAn Introduction to CSS Preprocessors
An Introduction to CSS Preprocessors
Miloš Sutanovac
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
Adam Englander
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHP
Adam Englander
 
Javascript fundamentals for php developers
Javascript fundamentals for php developersJavascript fundamentals for php developers
Javascript fundamentals for php developers
Chris Ramakers
 
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar PradhanAwesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Ajeet Singh Raina
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and Kibana
Prajal Kulkarni
 
CoreOS: Control Your Fleet
CoreOS: Control Your FleetCoreOS: Control Your Fleet
CoreOS: Control Your Fleet
Matthew Jones
 
JavaFX, because you're worth it
JavaFX, because you're worth itJavaFX, because you're worth it
JavaFX, because you're worth it
Thierry Wasylczenko
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
Zalando Technology
 
Application Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.key
Tim Bunce
 

Similar to Devinsampa nginx-scripting (20)

Noah Zoschke at Waza 2013: Heroku Secrets
Noah Zoschke at Waza 2013: Heroku SecretsNoah Zoschke at Waza 2013: Heroku Secrets
Noah Zoschke at Waza 2013: Heroku Secrets
 
Beginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at GoogleBeginner workshop to angularjs presentation at Google
Beginner workshop to angularjs presentation at Google
 
Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...
 
Marko Gargenta_Remixing android
Marko Gargenta_Remixing androidMarko Gargenta_Remixing android
Marko Gargenta_Remixing android
 
linux-namespaces.pdf
linux-namespaces.pdflinux-namespaces.pdf
linux-namespaces.pdf
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.
 
Keep it simple web development stack
Keep it simple web development stackKeep it simple web development stack
Keep it simple web development stack
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 
An Introduction to CSS Preprocessors
An Introduction to CSS PreprocessorsAn Introduction to CSS Preprocessors
An Introduction to CSS Preprocessors
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHP
 
Javascript fundamentals for php developers
Javascript fundamentals for php developersJavascript fundamentals for php developers
Javascript fundamentals for php developers
 
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar PradhanAwesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
 
Attack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and KibanaAttack monitoring using ElasticSearch Logstash and Kibana
Attack monitoring using ElasticSearch Logstash and Kibana
 
CoreOS: Control Your Fleet
CoreOS: Control Your FleetCoreOS: Control Your Fleet
CoreOS: Control Your Fleet
 
JavaFX, because you're worth it
JavaFX, because you're worth itJavaFX, because you're worth it
JavaFX, because you're worth it
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
 
Application Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.key
 

Recently uploaded

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 

Recently uploaded (20)

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

Devinsampa nginx-scripting

  • 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
  • 6.
  • 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
  • 10.
  • 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