Mod_lua for beginners Eric Covener, IBM November 2011.

Slides:



Advertisements
Similar presentations
Other Web Application Development Technologies. PHP.
Advertisements

Microsoft Research March 20, 2000 A Programming Language for Developing Interactive Web Services Claus Brabrand BRICS, University of Aarhus, Denmark.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Ruby (on Rails) CSE 190M, Spring 2009 Week 3. Web Programming in Ruby Ruby can be used to write dynamic web pages Similar to PHP, chunks of Ruby begins.
20-753: Fundamentals of Web Programming 1 Lecture 11: Web Server Case Study Fundamentals of Web Programming Lecture 11: Web Server Case Study.
Software Freedom Day th September 2007 Asia Pacific Institute of Information Technology Colombo, Sri Lanka. Nazly Ahmed Scripting The Web.
What is it? –Large Web sites that support commercial use cannot be written by hand What you’re going to learn –How a Web server and a database can be used.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
The World Wide Web and the Internet Dr Jim Briggs 1WUCM1.
SCRIPTING LANGUAGE. The first interactive shells were developed in the 1960s to enable remote operation of the first time-sharing systems, and these,
How Clients and Servers Work Together. Objectives Learn about the interaction of clients and servers Explore the features and functions of Web servers.
Apache : Installation, Configuration, Basic Security Presented by, Sandeep K Thopucherela, ECE Department.
PHP Scripting Language. Introduction “PHP” is an acronym for “PHP: Hypertext Preprocessor.” It is an interpreted, server-side scripting language. Originally.
Session-01. What is a Servlet? Servlet can be described in many ways, depending on the context: 1.Servlet is a technology i.e. used to create web application.
Understanding and Managing WebSphere V5
Securing LAMP: Linux, Apache, MySQL and PHP Track 2 Workshop PacNOG 7 July 1, 2010 Pago Pago, American Samoa.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
Server Side Scripting Norman White. Where do we do processing? Client side – Javascript (embed code in html) – Java applets (send java program to run.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 03.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
ITM352 PHP and Dynamic Web Pages: Server Side Processing.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 24 – Web Servers (PWS, IIS, Apache, Jigsaw) Outline 24.1Introduction 24.2Microsoft Personal.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
SIMPLE ROUTER The slide made by Salim Malakouti. Next we will create the Router  What do I we mean by a router?  Routers work similar to a map. It receives.
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
Let’s Wub Wub tutorial What is Wub? HTTP 1.1 Webserver Written by Colin McCormack 100% Tcl Web application framework Domain based.
1 Apache. 2 Module - Apache ♦ Overview This module focuses on configuring and customizing Apache web server. Apache is a commonly used Hypertext Transfer.
PHP and MySQL by Example COMP YL Professor Mattos.
Apache Web Server v. 2.2 Reference Manual Chapter 1 Compiling and Installing.
Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess AFNOG 11 Kigali, Rwanda May 2010 Dorcas Muthoni Courtesy: Hervey Allen.
The Web Architecture and ASP.NET. Slide 2 Review of the Web (1) It began with HTTP and HTML, which delivers static Web pages to browsers which would render.
2001 IT Conference RenoPage: 1 PHP 101 PHP – You can DO IT! Greg Lawler Brooks Institute of Photography February IT Conference Reno.
Dynamic web content HTTP and HTML: Berners-Lee’s Basics.
Apache Web Server Quick and Dirty for AfNOG 2015 (Originally by Joel Jaeggli for AfNOG 2007) ‏
© 2004 OPNET Technologies, Inc. All rights reserved. OPNET and OPNET product names are trademarks of OPNET Technologies, Inc. ARMing Apache David Carter.
Apache Web Server Quick and Dirty Evelyn NAMARA for AfNOG 2014 (Originally by Joel Jaeggli for AfNOG 2007) ‏
1 Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess AFNOG X Cairo, Egypt May 2009 Hervey Allen.
1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development.
The HTTP is a standard that all Web browsers and Web servers must speak in order for the Web portion of the Internet to work.
AxKit A member of the Apache XML project Ryan Maslyn Kyle Bechtel.
Martin Kruliš by Martin Kruliš (v1.1)1.
Apache HTTP Server from 10,000 feet An open source Apache feature overview and discussion.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
More than one site? Use multiple configuration files Use multiple configuration files  httpd –d {path}  Assumes “conf/httpd.conf” Logging transactions.
Introduction to mod_perl Issac Goldstand Mirimar Networks
Web Server Apache PHP HTTP Request User types URL into browser Address resolved if nec. We use directly Most browsers request.
(ITI310) By Eng. BASSEM ALSAID SESSIONS 10: Internet Information Services (IIS)
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
Web Cache. What is Cache? Cache is the storing of data temporarily to improve performance. Cache exist in a variety of areas such as your CPU, Hard Disk.
CGS 3066: Web Programming and Design Spring 2016 Introduction to Server-Side Programming.
NWCLUG 04/06/2010 Jared Moore L A M P.
CGS 3066: Web Programming and Design Spring 2017
Top 8 Best Programming Languages To Learn
Node.Js Server Side Javascript
Introduction to Dynamic Web Programming
ITM352 PHP and Dynamic Web Pages: Server Side Processing 1.
Apache Web Server v. 2.2 Reference Manual
Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess
Node.js Express Web Applications
Processes The most important processes used in Web-based systems and their internal organization.
PHP / MySQL Introduction
Node.Js Server Side Javascript
SVTRAININGS. SVTRAININGS Python Overview  Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed.
Common Gateway Interface (CGI current version 1.1)
APACHE WEB SERVER.
Presentation transcript:

mod_lua for beginners Eric Covener, IBM November 2011

About Me  Eric Covener  Apache HTTP Server and WebSphere Application Server Development at IBM.  Contributor to Apache HTTP Server, Apache Portable Runtime, and Apache OpenWebBeans.  Frequent supporter on freenode #httpd and the HTTPD users mailing list

Agenda  Introduction to Lua  Introduction to mod_lua  mod_lua recipes for familiar problems  The future  Wrap-up

What is Lua?  “Lua is a powerful, fast, lightweight, embeddable scripting language” Basic syntax familiar to occasional users of C or interpreted languages such as JavaScript, PHP, PERL, … #!/usr/bin/lua io.write("What's your name? ") local name = io.read("*line") print("Hello, ", name)

More on Lua  Lua is used as the scripting engine many popular large applications  World of Warcraft, VLC, Wireshark, RPM  Extensions allow Lua scripts to exploit popular libraries such as memcached, mysql, GD, curl, expat, sockets.  The programs embedding Lua are expected to provide useful routines.  Basic Features: Simple syntax, C-like control structures, I/O, basic regex  Advanced Features:  Co-routines, closures, OOP

What is mod_lua?  mod_lua allows users to write Lua scripts to extend and modify the webserver  Handling the response in a Lua script  Changing request processing metadata (think SetEnvIf, RequestHeader, Header, and RewriteRule)  Implementation of Authentication, Authorization, Access Control  Much like a compiled Apache HTTP Server module, or scripts written in mod_perl.

Getting mod_lua  Part of Apache HTTP Server 2.3.x (and later)  Must be enabled during build (explicitly, or via – enable-mods-shared=[really]all)  Lua interpreter (and –dev counterpart) must be available at build time  Packaged with most Linux distributions  Source tarball is 200k and has no dependencies (doesn’t even use autoconf)

A simple mod_lua handler  The simplest way a traditional module (or a mod_lua script) can participate in a request is by acting as the “handler”, or generator, for the response. 1 function handle(r) 2 r.content_type = "text/html" 3 local query = r:parseargs() 4 if query.name == nil then 5 r:puts("What's your name? “, 6 “ ") 7 else 8 r:puts("Hello, ", r:escape_html(query.name)); 9 end 10 end

Invoking a Lua handler  A few different ways to teach mod_lua about our script  AddHandler lua-script.lua  LuaMapHandler  LuaMapHandler /hello /path/to/luascripts/hello.lua  LuaQuickHandler   No external script file required, lives in httpd.conf

Handler performance SourceRequests/second static4300 mod_php2900 mod_lua2400 CGI 600 Crude performance test of a short “Hello, world” page.

Apache Module Primer  Traditional Apache modules can do more than just generate the response  The participate in designated “hooks” with other modules  Mapping a URI to the filesystem  Performing authentication  Setting mime-types  mod_lua allows Lua scripts to participate the same way

Noteworthy hooks quick_handler translate_name URI -> filename access_checker user-independent access control check_userid authentication auth_checker authorization fixups

Redirect to SSL 1 require "apache2" 2 function redirect_ssl(r) 3 local https = r:ssl_var_lookup("HTTPS") 4 if (https == nil or https == "" or https == "off") then 5 r.err_headers_out['Location'] = string.gsub(r:construct_url(r.uri), " " 6 return apache2.HTTP_MOVED_TEMPORARILY 7 end 8 return apache2.DECLINED 9 end

Maintenance page 1 require "apache2“ 2 require “posix" 3 4 function maint(r) 5 if posix.stat(“/tmp/maintenance”) ~= nil then 6 r:puts(“site temporarily unavailable") 7 r.status = 503; 8 return apache2.OK 9 else 10 return apache2.DECLINED 11 end 12 end

Rewrite based on Query 1 function rewrite_query(r) 2 local query = r:parseargs() 3 if query.foo ~= nil and 4 query.bar ~= nil then 5 r.uri = r.uri.. 6 "/".. query.foo.. 7 "/".. query.bar 8 end 9 return apache2.DECLINED 10 end

mod_lua in place of mod_rewrite  Pros  Proper programming language with control structures, subroutines  Less baggage  Custom logging  Easier to unit test  Easier/less fragile to extend  Cons  Only basic regular expression by default  Less source material on the web  No htaccess for most recipes

Serving pre-compressed files LuaHookMapToStorage... 1 require "apache2" 2 require "posix" 3 function gz(r) 4 local acceptEncoding = 5 r.headers_in['Accept-Encoding'] 6 if (r.filename and acceptEncoding and 7 string.find(acceptEncoding, "gzip")) then 8 if posix.stat(r.filename.. ".gz") then 9 r.filename = r.filename.. ".gz" 10 r.headers_out['Vary'] = "Accept-Encoding" 11 end 12 end 13 return apache2.DECLINED 14 end

Check Authorization LuaHookAuthChecker /path/to/authz.lua authz … 1 require "apache2" 2 require "posix" 3 4 function authz(r) 5 if r.user == "bob" then 6 local hour = tonumber(os.date("%H")) 7 if hour > 8 and hour < 17 then 8 return end 10 end 11 return apache2.DECLINED 12 end

Basic-if-no-cert LuaHookAuthCheckUserID /path/to/auth.lua \ authn early 1 function authn(r) 2 local user = 3 r:ssl_var_lookup("SSL_CLIENT_S_DN_CN") 4 if user == nil or user == "" then 5 return apache2.DECLINED 6 end 7 r.user = user 8 return apache2.OK 9 end

mod_lua's future  HTTP Request/Response filters  More Apache API access  Configuration in mod_lua  More mod_lua examples  Join in and help decide!

Conclusion  Flexible alternative to mod_setenvif/mod_rewrite/mod_headers recipes.  Lowers barriers to quickly interact with HTTP Server API in what would be short modules  Lightweight scripting language for handlers  Input needed from users, tell us what you want to write in Lua!

Sources  mod_lua manual – mod_lua.html  The Apache Modules Book –  Programming in Lua –

Contact  Eric Covener