User Tools

Site Tools


admin:embed_the_power_of_lua_into_nginx

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
admin:embed_the_power_of_lua_into_nginx [2015/09/04 23:46] – created ryanadmin:embed_the_power_of_lua_into_nginx [2015/09/05 08:24] (current) – [Testing] ryan
Line 183: Line 183:
 ls -al rpmbuild/RPMS/x86_64/nginx-lua-* ls -al rpmbuild/RPMS/x86_64/nginx-lua-*
  
-yum localinstall nginx-lua-1.8.0-1.el6.ngx.x86_64.rpm +yum localinstall nginx-lua-1.8.0-1.el6.rdemo.x86_64.rpm 
 </code> </code>
  
 ==== Testing ==== ==== Testing ====
  
-To test out the new functionality, we modify the server block to call a Lua script on each request:+To test out the new functionality, we modify the server block to call a Lua script on any request:
 <file c default.conf> <file c default.conf>
 server { server {
Line 201: Line 201:
 } }
 </file> </file>
-Our test file is called ''reqhash.lua'' and is located in the ''lua'' folder of the server path (default location is ''/etc/nginx''). It will be run on every request received by the server.+Our test file is called ''reqhash.lua'' and is located in the ''lua'' folder of the server path (default location is ''/etc/nginx''). When the first request comes in, Nginx will load the script from disk and pass it to LuaJIT, that will compile parts of it to native code as they are invoked. Every subsequent request will run the cached machine code.
  
 The code is pretty straightforward: The code is pretty straightforward:
Line 214: Line 214:
 ngx.header.content_type = 'text/plain'; ngx.header.content_type = 'text/plain';
 for k, v in pairs(headers) do for k, v in pairs(headers) do
-    print(string.format("%s\t%s: %s", base64(hmacdigest('sha256', v, k, true)), tostring(k)tostring(v)))+    print(string.format("%s\t%s: %s", base64(hmacdigest('sha256', v, k, true)), k, v))
 end end
 </file> </file>
admin/embed_the_power_of_lua_into_nginx.1441410374.txt.gz · Last modified: 2015/09/04 23:46 by ryan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki