1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 This file is generated from xml source: DO NOT EDIT
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8 <title>mod_lua - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
12 <script src="../style/scripts/prettify.js" type="text/javascript">
15 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
17 <div id="page-header">
18 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
19 <p class="apache">Apache HTTP Server Version 2.5</p>
20 <img alt="" src="../images/feather.gif" /></div>
21 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
23 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.5</a> > <a href="./">Modules</a></div>
24 <div id="page-content">
25 <div id="preamble"><h1>Apache Module mod_lua</h1>
27 <p><span>Available Languages: </span><a href="../en/mod/mod_lua.html" title="English"> en </a> |
28 <a href="../fr/mod/mod_lua.html" hreflang="fr" rel="alternate" title="Français"> fr </a></p>
30 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides Lua hooks into various portions of the httpd
31 request processing</td></tr>
32 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
33 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>lua_module</td></tr>
34 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_lua.c</td></tr>
35 <tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>2.3 and later</td></tr></table>
38 <p>This module allows the server to be extended with scripts written in the
39 Lua programming language. The extension points (hooks) available with
40 <code class="module"><a href="../mod/mod_lua.html">mod_lua</a></code> include many of the hooks available to
41 natively compiled Apache HTTP Server modules, such as mapping requests to
42 files, generating dynamic responses, access control, authentication, and
45 <p>More information on the Lua programming language can be found at the
46 <a href="http://www.lua.org/">the Lua website</a>.</p>
48 <div class="note"><code>mod_lua</code> is still in experimental state.
49 Until it is declared stable, usage and behavior may change
50 at any time, even between stable releases of the 2.4.x series.
51 Be sure to check the CHANGES file before upgrading.</div>
53 <div class="warning"><h3>Warning</h3>
54 <p>This module holds a great deal of power over httpd, which is both a
55 strength and a potential security risk. It is <strong>not</strong> recommended
56 that you use this module on a server that is shared with users you do not
57 trust, as it can be abused to change the internal workings of httpd.</p>
61 <div id="quickview"><h3 class="directives">Directives</h3>
63 <li><img alt="" src="../images/down.gif" /> <a href="#luaauthzprovider">LuaAuthzProvider</a></li>
64 <li><img alt="" src="../images/down.gif" /> <a href="#luacodecache">LuaCodeCache</a></li>
65 <li><img alt="" src="../images/down.gif" /> <a href="#luahookaccesschecker">LuaHookAccessChecker</a></li>
66 <li><img alt="" src="../images/down.gif" /> <a href="#luahookauthchecker">LuaHookAuthChecker</a></li>
67 <li><img alt="" src="../images/down.gif" /> <a href="#luahookcheckuserid">LuaHookCheckUserID</a></li>
68 <li><img alt="" src="../images/down.gif" /> <a href="#luahookfixups">LuaHookFixups</a></li>
69 <li><img alt="" src="../images/down.gif" /> <a href="#luahookinsertfilter">LuaHookInsertFilter</a></li>
70 <li><img alt="" src="../images/down.gif" /> <a href="#luahookmaptostorage">LuaHookMapToStorage</a></li>
71 <li><img alt="" src="../images/down.gif" /> <a href="#luahooktranslatename">LuaHookTranslateName</a></li>
72 <li><img alt="" src="../images/down.gif" /> <a href="#luahooktypechecker">LuaHookTypeChecker</a></li>
73 <li><img alt="" src="../images/down.gif" /> <a href="#luainherit">LuaInherit</a></li>
74 <li><img alt="" src="../images/down.gif" /> <a href="#luamaphandler">LuaMapHandler</a></li>
75 <li><img alt="" src="../images/down.gif" /> <a href="#luapackagecpath">LuaPackageCPath</a></li>
76 <li><img alt="" src="../images/down.gif" /> <a href="#luapackagepath">LuaPackagePath</a></li>
77 <li><img alt="" src="../images/down.gif" /> <a href="#luaquickhandler">LuaQuickHandler</a></li>
78 <li><img alt="" src="../images/down.gif" /> <a href="#luaroot">LuaRoot</a></li>
79 <li><img alt="" src="../images/down.gif" /> <a href="#luascope">LuaScope</a></li>
83 <li><img alt="" src="../images/down.gif" /> <a href="#basicconf">Basic Configuration</a></li>
84 <li><img alt="" src="../images/down.gif" /> <a href="#writinghandlers">Writing Handlers</a></li>
85 <li><img alt="" src="../images/down.gif" /> <a href="#writingauthzproviders">Writing Authorization Providers</a></li>
86 <li><img alt="" src="../images/down.gif" /> <a href="#writinghooks">Writing Hooks</a></li>
87 <li><img alt="" src="../images/down.gif" /> <a href="#datastructures">Data Structures</a></li>
88 <li><img alt="" src="../images/down.gif" /> <a href="#logging">Logging Functions</a></li>
89 <li><img alt="" src="../images/down.gif" /> <a href="#apache2">apache2 Package</a></li>
90 </ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
91 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
93 <h2><a name="basicconf" id="basicconf">Basic Configuration</a></h2>
95 <p>The basic module loading directive is</p>
97 <pre class="prettyprint lang-config">
98 LoadModule lua_module modules/mod_lua.so
103 <code>mod_lua</code> provides a handler named <code>lua-script</code>,
104 which can be used with an <code>AddHandler</code> directive:</p>
106 <pre class="prettyprint lang-config">
107 AddHandler lua-script .lua
112 This will cause <code>mod_lua</code> to handle requests for files
113 ending in <code>.lua</code> by invoking that file's
114 <code>handle</code> function.
117 <p>For more flexibility, see <code class="directive">LuaMapHandler</code>.
120 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
121 <div class="section">
122 <h2><a name="writinghandlers" id="writinghandlers">Writing Handlers</a></h2>
123 <p> In the Apache HTTP Server API, the handler is a specific kind of hook
124 responsible for generating the response. Examples of modules that include a
125 handler are <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code>, <code class="module"><a href="../mod/mod_cgi.html">mod_cgi</a></code>,
126 and <code class="module"><a href="../mod/mod_status.html">mod_status</a></code>.</p>
128 <p><code>mod_lua</code> always looks to invoke a Lua function for the handler, rather than
129 just evaluating a script body CGI style. A handler function looks
130 something like this:</p>
133 <pre class="prettyprint lang-lua">
134 <strong>example.lua</strong><br />
140 This is the default method name for Lua handlers, see the optional
141 function-name in the LuaMapHandler directive to choose a different
145 r.content_type = "text/plain"
146 r:puts("Hello Lua World!\n")
148 if r.method == 'GET' then
149 for k, v in pairs( r:parseargs() ) do
150 r:puts( string.format("%s: %s\n", k, v) )
152 elseif r.method == 'POST' then
153 for k, v in pairs( r:parsebody() ) do
154 r:puts( string.format("%s: %s\n", k, v) )
157 r:puts("Unsupported HTTP method " .. r.method)
164 This handler function just prints out the uri or form encoded
165 arguments to a plaintext page.
169 This means (and in fact encourages) that you can have multiple
170 handlers (or hooks, or filters) in the same script.
173 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
174 <div class="section">
175 <h2><a name="writingauthzproviders" id="writingauthzproviders">Writing Authorization Providers</a></h2>
178 <p><code class="module"><a href="../mod/mod_authz_core.html">mod_authz_core</a></code> provides a high-level interface to
179 authorization that is much easier to use than using into the relevant
180 hooks directly. The first argument to the
181 <code class="directive"><a href="../mod/mod_authz_core.html#require">Require</a></code> directive gives
182 the name of the responsible authorization provider. For any
183 <code class="directive"><a href="../mod/mod_authz_core.html#require">Require</a></code> line,
184 <code class="module"><a href="../mod/mod_authz_core.html">mod_authz_core</a></code> will call the authorization provider
185 of the given name, passing the rest of the line as parameters. The
186 provider will then check authorization and pass the result as return
189 <p>The authz provider is normally called before authentication. If it needs to
190 know the authenticated user name (or if the user will be authenticated at
191 all), the provider must return <code>apache2.AUTHZ_DENIED_NO_USER</code>.
192 This will cause authentication to proceed and the authz provider to be
193 called a second time.</p>
195 <p>The following authz provider function takes two arguments, one ip
196 address and one user name. It will allow access from the given ip address
197 without authentication, or if the authenticated user matches the second
200 <pre class="prettyprint lang-lua">
201 <strong>authz_provider.lua</strong><br />
205 function authz_check_foo(r, ip, user)
206 if r.useragent_ip == ip then
207 return apache2.AUTHZ_GRANTED
208 elseif r.user == nil then
209 return apache2.AUTHZ_DENIED_NO_USER
210 elseif r.user == user then
211 return apache2.AUTHZ_GRANTED
213 return apache2.AUTHZ_DENIED
219 <p>The following configuration registers this function as provider
220 <code>foo</code> and configures it for URL <code>/</code>:</p>
221 <pre class="prettyprint lang-config">
222 LuaAuthzProvider foo authz_provider.lua authz_check_foo
224 Require foo 10.1.2.3 john_doe
229 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
230 <div class="section">
231 <h2><a name="writinghooks" id="writinghooks">Writing Hooks</a></h2>
233 <p>Hook functions are how modules (and Lua scripts) participate in the
234 processing of requests. Each type of hook exposed by the server exists for
235 a specific purposes such as mapping requests to the filesystem,
236 performing access control, or setting mimetypes:</p>
238 <table class="bordered"><tr class="header">
240 <th>mod_lua directive</th>
244 <td>Quick handler</td>
245 <td><code class="directive"><a href="#luaquickhandler">LuaQuickHandler</a></code></td>
246 <td>This is the first hook that will be called after a request has
247 been mapped to a host or virtual host</td>
250 <td>Translate name</td>
251 <td><code class="directive"><a href="#luahooktranslatename">LuaHookTranslateName</a></code></td>
252 <td>This phase translates the requested URI into a filename on the
253 system. Modules such as <code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code> and
254 <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> operate in this phase.</td>
257 <td>Map to storage</td>
258 <td><code class="directive"><a href="#luahookmaptostorage">LuaHookMapToStorage</a></code></td>
259 <td>This phase maps files to their physical, cached or external/proxied storage.
260 It can be used by proxy or caching modules</td>
263 <td>Check Access</td>
264 <td><code class="directive"><a href="#luahookaccesschecker">LuaHookAccessChecker</a></code></td>
265 <td>This phase checks whether a client has access to a resource. This
266 phase is run before the user is authenticated, so beware.
270 <td>Check User ID</td>
271 <td><code class="directive"><a href="#luahookcheckuserid">LuaHookCheckUserID</a></code></td>
272 <td>This phase it used to check the negotiated user ID</td>
275 <td>Check Authorization</td>
276 <td><code class="directive"><a href="#luahookauthchecker">LuaHookAuthChecker</a></code> or
277 <code class="directive"><a href="#luaauthzprovider">LuaAuthzProvider</a></code></td>
278 <td>This phase authorizes a user based on the negotiated credentials, such as
279 user ID, client certificate etc.
284 <td><code class="directive"><a href="#luahooktypechecker">LuaHookTypeChecker</a></code></td>
285 <td>This phase checks the requested file and assigns a content type and
290 <td><code class="directive"><a href="#luahookfixups">LuaHookFixups</a></code></td>
291 <td>This is the final "fix anything" phase before the content handlers
292 are run. Any last-minute changes to the request should be made here.</td>
295 <td>Content handler</td>
296 <td>fx. <code>.lua</code> files or through <code class="directive"><a href="#luamaphandler">LuaMapHandler</a></code></td>
297 <td>This is where the content is handled. Files are read, parsed, some are run,
298 and the result is sent to the client</td>
303 <td>Once a request has been handled, it enters several logging phases,
304 which logs the request in either the error or access log</td>
308 <p>Hook functions are passed the request object as their only argument
309 (except for LuaAuthzProvider, which also gets passed the arguments from
310 the Require directive).
311 They can return any value, depending on the hook, but most commonly
312 they'll return OK, DONE, or DECLINED, which you can write in lua as
313 <code>apache2.OK</code>, <code>apache2.DONE</code>, or
314 <code>apache2.DECLINED</code>, or else an HTTP status code.</p>
317 <pre class="prettyprint lang-lua">
318 <strong>translate_name.lua</strong><br />
319 -- example hook that rewrites the URI to a filesystem path.
323 function translate_name(r)
324 if r.uri == "/translate-name" then
325 r.filename = r.document_root .. "/find_me.txt"
328 -- we don't care about this URL, give another module a chance
329 return apache2.DECLINED
335 <pre class="prettyprint lang-lua">
336 <strong>translate_name2.lua</strong><br />
337 --[[ example hook that rewrites one URI to another URI. It returns a
338 apache2.DECLINED to give other URL mappers a chance to work on the
339 substitution, including the core translate_name hook which maps based
342 Note: Use the early/late flags in the directive to make it run before
348 function translate_name(r)
349 if r.uri == "/translate-name" then
350 r.uri = "/find_me.txt"
351 return apache2.DECLINED
353 return apache2.DECLINED
357 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
358 <div class="section">
359 <h2><a name="datastructures" id="datastructures">Data Structures</a></h2>
364 <p>The request_rec is mapped in as a userdata. It has a metatable
365 which lets you do useful things with it. For the most part it
366 has the same fields as the request_rec struct, many of which are writeable as
367 well as readable. (The table fields' content can be changed, but the
368 fields themselves cannot be set to different tables.)</p>
370 <table class="bordered"><tr class="header">
371 <th><strong>Name</strong></th>
372 <th><strong>Lua type</strong></th>
373 <th><strong>Writable</strong></th>
374 <th><strong>Description</strong></th>
377 <td><code>allowoverrides</code></td>
380 <td>The AllowOverride options applied to the current request.</td>
383 <td><code>ap_auth_type</code></td>
386 <td>If an authentication check was made, this is set to the type
387 of authentication (f.x. <code>basic</code>)</td>
390 <td><code>args</code></td>
393 <td>The query string arguments extracted from the request
394 (f.x. <code>foo=bar&name=johnsmith</code>)</td>
397 <td><code>assbackwards</code></td>
400 <td>Set to true if this is an HTTP/0.9 style request
401 (e.g. <code>GET /foo</code> (with no headers) )</td>
404 <td><code>auth_name</code></td>
407 <td>The realm name used for authorization (if applicable).</td>
410 <td><code>banner</code></td>
413 <td>The server banner, f.x. <code>Apache HTTP Server/2.4.3 openssl/0.9.8c</code></td>
416 <td><code>basic_auth_pw</code></td>
419 <td>The basic auth password sent with this request, if any</td>
422 <td><code>canonical_filename</code></td>
425 <td>The canonical filename of the request</td>
428 <td><code>content_encoding</code></td>
431 <td>The content encoding of the current request</td>
434 <td><code>content_type</code></td>
437 <td>The content type of the current request, as determined in the
438 type_check phase (f.x. <code>image/gif</code> or <code>text/html</code>)</td>
441 <td><code>context_prefix</code></td>
447 <td><code>context_document_root</code></td>
453 <td><code>document_root</code></td>
456 <td>The document root of the host</td>
459 <td><code>err_headers_out</code></td>
462 <td>MIME header environment for the response, printed even on errors and
463 persist across internal redirects</td>
466 <td><code>filename</code></td>
469 <td>The file name that the request maps to, f.x. /www/example.com/foo.txt. This can be
470 changed in the translate-name or map-to-storage phases of a request to allow the
471 default handler (or script handlers) to serve a different file than what was requested.</td>
474 <td><code>handler</code></td>
477 <td>The name of the <a href="../handler.html">handler</a> that should serve this request, f.x.
478 <code>lua-script</code> if it is to be served by mod_lua. This is typically set by the
479 <code class="directive"><a href="../mod/mod_mime.html#addhandler">AddHandler</a></code> or <code class="directive"><a href="../mod/core.html#sethandler">SetHandler</a></code>
480 directives, but could also be set via mod_lua to allow another handler to serve up a specific request
481 that would otherwise not be served by it.
485 <td><code>headers_in</code></td>
488 <td>MIME header environment from the request. This contains headers such as <code>Host,
489 User-Agent, Referer</code> and so on.</td>
492 <td><code>headers_out</code></td>
495 <td>MIME header environment for the response.</td>
498 <td><code>hostname</code></td>
501 <td>The host name, as set by the <code>Host:</code> header or by a full URI.</td>
504 <td><code>is_https</code></td>
507 <td>Whether or not this request is done via HTTPS</td>
510 <td><code>is_initial_req</code></td>
513 <td>Whether this request is the initial request or a sub-request</td>
516 <td><code>limit_req_body</code></td>
519 <td>The size limit of the request body for this request, or 0 if no limit.</td>
522 <td><code>log_id</code></td>
525 <td>The ID to identify request in access and error log.</td>
528 <td><code>method</code></td>
531 <td>The request method, f.x. <code>GET</code> or <code>POST</code>.</td>
534 <td><code>notes</code></td>
537 <td>A list of notes that can be passed on from one module to another.</td>
540 <td><code>options</code></td>
543 <td>The Options directive applied to the current request.</td>
546 <td><code>path_info</code></td>
549 <td>The PATH_INFO extracted from this request.</td>
552 <td><code>port</code></td>
555 <td>The server port used by the request.</td>
558 <td><code>protocol</code></td>
561 <td>The protocol used, f.x. <code>HTTP/1.1</code></td>
564 <td><code>proxyreq</code></td>
567 <td>Denotes whether this is a proxy request or not. This value is generally set in
568 the post_read_request/translate_name phase of a request.</td>
571 <td><code>range</code></td>
574 <td>The contents of the <code>Range:</code> header.</td>
577 <td><code>remaining</code></td>
580 <td>The number of bytes remaining to be read from the request body.</td>
583 <td><code>server_built</code></td>
586 <td>The time the server executable was built.</td>
589 <td><code>server_name</code></td>
592 <td>The server name for this request.</td>
595 <td><code>some_auth_required</code></td>
598 <td>Whether some authorization is/was required for this request.</td>
601 <td><code>subprocess_env</code></td>
604 <td>The environment variables set for this request.</td>
607 <td><code>started</code></td>
610 <td>The time the server was (re)started, in seconds since the epoch (Jan 1st, 1970)</td>
613 <td><code>status</code></td>
616 <td>The (current) HTTP return code for this request, f.x. <code>200</code> or <code>404</code>.</td>
619 <td><code>the_request</code></td>
622 <td>The request string as sent by the client, f.x. <code>GET /foo/bar HTTP/1.1</code>.</td>
625 <td><code>unparsed_uri</code></td>
628 <td>The unparsed URI of the request</td>
631 <td><code>uri</code></td>
634 <td>The URI after it has been parsed by httpd</td>
637 <td><code>user</code></td>
640 <td>If an authentication check has been made, this is set to the name of the authenticated user.</td>
643 <td><code>useragent_ip</code></td>
646 <td>The IP of the user agent making the request</td>
650 <p>The request_rec has (at least) the following methods:</p>
652 <pre class="prettyprint lang-lua">
653 r:flush() -- flushes the output buffer
657 <pre class="prettyprint lang-lua">
658 r:addoutputfilter(name|function) -- add an output filter
662 <pre class="prettyprint lang-lua">
663 r:sendfile(filename) -- sends an entire file to the client, using sendfile if supported by the current platform
667 <pre class="prettyprint lang-lua">
668 r:parseargs() -- returns a Lua table containing the request's query string arguments
672 <pre class="prettyprint lang-lua">
673 r:parsebody() -- parse any POST data in the request and return it as a Lua table
677 <pre class="prettyprint lang-lua">
678 r:puts("hello", " world", "!") -- print to response body
682 <pre class="prettyprint lang-lua">
683 r:write("a single string") -- print to response body
687 <pre class="prettyprint lang-lua">
688 r:escape_html("<html>test</html>") -- Escapes HTML code and returns the escaped result
694 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
695 <div class="section">
696 <h2><a name="logging" id="logging">Logging Functions</a></h2>
698 <pre class="prettyprint lang-lua">
699 -- examples of logging messages<br />
700 r:trace1("This is a trace log message") -- trace1 through trace8 can be used <br />
701 r:debug("This is a debug log message")<br />
702 r:info("This is an info log message")<br />
703 r:notice("This is an notice log message")<br />
704 r:warn("This is an warn log message")<br />
705 r:err("This is an err log message")<br />
706 r:alert("This is an alert log message")<br />
707 r:crit("This is an crit log message")<br />
708 r:emerg("This is an emerg log message")<br />
712 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
713 <div class="section">
714 <h2><a name="apache2" id="apache2">apache2 Package</a></h2>
715 <p>A package named <code>apache2</code> is available with (at least) the following contents.</p>
718 <dd>internal constant OK. Handlers should return this if they've
719 handled the request.</dd>
720 <dt>apache2.DECLINED</dt>
721 <dd>internal constant DECLINED. Handlers should return this if
722 they are not going to handle the request.</dd>
723 <dt>apache2.DONE</dt>
724 <dd>internal constant DONE.</dd>
725 <dt>apache2.version</dt>
726 <dd>Apache HTTP server version string</dd>
727 <dt>apache2.HTTP_MOVED_TEMPORARILY</dt>
728 <dd>HTTP status code</dd>
729 <dt>apache2.PROXYREQ_NONE, apache2.PROXYREQ_PROXY, apache2.PROXYREQ_REVERSE, apache2.PROXYREQ_RESPONSE</dt>
730 <dd>internal constants used by <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code></dd>
731 <dt>apache2.AUTHZ_DENIED, apache2.AUTHZ_GRANTED, apache2.AUTHZ_NEUTRAL, apache2.AUTHZ_GENERAL_ERROR, apache2.AUTHZ_DENIED_NO_USER</dt>
732 <dd>internal constants used by <code class="module"><a href="../mod/mod_authz_core.html">mod_authz_core</a></code></dd>
735 <p>(Other HTTP status codes are not yet implemented.)</p>
737 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
738 <div class="directive-section"><h2><a name="LuaAuthzProvider" id="LuaAuthzProvider">LuaAuthzProvider</a> <a name="luaauthzprovider" id="luaauthzprovider">Directive</a></h2>
739 <table class="directive">
740 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Plug an authorization provider function into <code class="module"><a href="../mod/mod_authz_core.html">mod_authz_core</a></code>
742 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaAuthzProvider provider_name /path/to/lua/script.lua function_name</code></td></tr>
743 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
744 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
745 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
746 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>2.5.0 and later</td></tr>
748 <p>After a lua function has been registered as authorization provider, it can be used
749 with the <code class="directive"><a href="../mod/mod_authz_core.html#require">Require</a></code> directive:</p>
751 <pre class="prettyprint lang-config">
752 LuaRoot /usr/local/apache2/lua
753 LuaAuthzProvider foo authz.lua authz_check_foo
759 <pre class="prettyprint lang-lua">
761 function authz_check_foo(r, who)
762 if r.user ~= who then return apache2.AUTHZ_DENIED
763 return apache2.AUTHZ_GRANTED
771 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
772 <div class="directive-section"><h2><a name="LuaCodeCache" id="LuaCodeCache">LuaCodeCache</a> <a name="luacodecache" id="luacodecache">Directive</a></h2>
773 <table class="directive">
774 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Configure the compiled code cache.</td></tr>
775 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaCodeCache stat|forever|never</code></td></tr>
776 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaCodeCache stat</code></td></tr>
777 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
778 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
779 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
780 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
782 Specify the behavior of the in-memory code cache. The default
783 is stat, which stats the top level script (not any included
784 ones) each time that file is needed, and reloads it if the
785 modified time indicates it is newer than the one it has
786 already loaded. The other values cause it to keep the file
787 cached forever (don't stat and replace) or to never cache the
790 <p>In general stat or forever is good for production, and stat or never
793 <div class="example"><h3>Examples:</h3><pre class="prettyprint lang-config">
802 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
803 <div class="directive-section"><h2><a name="LuaHookAccessChecker" id="LuaHookAccessChecker">LuaHookAccessChecker</a> <a name="luahookaccesschecker" id="luahookaccesschecker">Directive</a></h2>
804 <table class="directive">
805 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the access_checker phase of request processing</td></tr>
806 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookAccessChecker /path/to/lua/script.lua hook_function_name [early|late]</code></td></tr>
807 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
808 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
809 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
810 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
811 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The optional third argument is supported in 2.3.15 and later</td></tr>
813 <p>Add your hook to the access_checker phase. An access checker
814 hook function usually returns OK, DECLINED, or HTTP_FORBIDDEN.</p>
815 <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late"
816 control when this script runs relative to other modules.</p></div>
819 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
820 <div class="directive-section"><h2><a name="LuaHookAuthChecker" id="LuaHookAuthChecker">LuaHookAuthChecker</a> <a name="luahookauthchecker" id="luahookauthchecker">Directive</a></h2>
821 <table class="directive">
822 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the auth_checker phase of request processing</td></tr>
823 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookAuthChecker /path/to/lua/script.lua hook_function_name [early|late]</code></td></tr>
824 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
825 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
826 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
827 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
828 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The optional third argument is supported in 2.3.15 and later</td></tr>
830 <p>Invoke a lua function in the auth_checker phase of processing
831 a request. This can be used to implement arbitrary authentication
832 and authorization checking. A very simple example:
834 <pre class="prettyprint lang-lua">
837 -- fake authcheck hook
838 -- If request has no auth info, set the response header and
839 -- return a 401 to ask the browser for basic auth info.
840 -- If request has auth info, don't actually look at it, just
841 -- pretend we got userid 'foo' and validated it.
842 -- Then check if the userid is 'foo' and accept the request.
843 function authcheck_hook(r)
845 -- look for auth info
846 auth = r.headers_in['Authorization']
852 if r.user == nil then
853 r:debug("authcheck: user is nil, returning 401")
854 r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
856 elseif r.user == "foo" then
857 r:debug('user foo: OK')
859 r:debug("authcheck: user='" .. r.user .. "'")
860 r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
867 <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late"
868 control when this script runs relative to other modules.</p></div>
871 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
872 <div class="directive-section"><h2><a name="LuaHookCheckUserID" id="LuaHookCheckUserID">LuaHookCheckUserID</a> <a name="luahookcheckuserid" id="luahookcheckuserid">Directive</a></h2>
873 <table class="directive">
874 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the check_user_id phase of request processing</td></tr>
875 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookCheckUserID /path/to/lua/script.lua hook_function_name [early|late]</code></td></tr>
876 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
877 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
878 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
879 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
880 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The optional third argument is supported in 2.3.15 and later</td></tr>
882 <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late"
883 control when this script runs relative to other modules.</p></div>
886 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
887 <div class="directive-section"><h2><a name="LuaHookFixups" id="LuaHookFixups">LuaHookFixups</a> <a name="luahookfixups" id="luahookfixups">Directive</a></h2>
888 <table class="directive">
889 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the fixups phase of a request
891 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookFixups /path/to/lua/script.lua hook_function_name</code></td></tr>
892 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
893 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
894 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
895 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
898 Just like LuaHookTranslateName, but executed at the fixups phase
902 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
903 <div class="directive-section"><h2><a name="LuaHookInsertFilter" id="LuaHookInsertFilter">LuaHookInsertFilter</a> <a name="luahookinsertfilter" id="luahookinsertfilter">Directive</a></h2>
904 <table class="directive">
905 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the insert_filter phase of request processing</td></tr>
906 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookInsertFilter /path/to/lua/script.lua hook_function_name</code></td></tr>
907 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
908 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
909 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
910 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
911 </table><p>Not Yet Implemented</p>
913 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
914 <div class="directive-section"><h2><a name="LuaHookMapToStorage" id="LuaHookMapToStorage">LuaHookMapToStorage</a> <a name="luahookmaptostorage" id="luahookmaptostorage">Directive</a></h2>
915 <table class="directive">
916 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the map_to_storage phase of request processing</td></tr>
917 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookMapToStorage /path/to/lua/script.lua hook_function_name</code></td></tr>
918 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
919 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
920 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
921 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
923 <p>Like <code class="directive">LuaHookTranslateName</code> but executed at the
924 map-to-storage phase of a request. Modules like mod_cache run at this phase,
925 which makes for an interesting example on what to do here:</p>
926 <pre class="prettyprint lang-config">
927 LuaHookMapToStorage /path/to/lua/script.lua check_cache
930 <pre class="prettyprint lang-lua">
934 function read_file(filename)
935 local input = io.open(filename, "r")
937 local data = input:read("*a")
938 cached_files[filename] = data
939 file = cached_files[filename]
942 return cached_files[filename]
945 function check_cache(r)
946 if r.filename:match("%.png$") then -- Only match PNG files
947 local file = cached_files[r.filename] -- Check cache entries
949 file = read_file(r.filename) -- Read file into cache
951 if file then -- If file exists, write it out
954 r:info(("Sent %s to client from cache"):format(r.filename))
955 return apache2.DONE -- skip default handler for PNG files
958 return apache2.DECLINED -- If we had nothing to do, let others serve this.
965 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
966 <div class="directive-section"><h2><a name="LuaHookTranslateName" id="LuaHookTranslateName">LuaHookTranslateName</a> <a name="luahooktranslatename" id="luahooktranslatename">Directive</a></h2>
967 <table class="directive">
968 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the translate name phase of request processing</td></tr>
969 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookTranslateName /path/to/lua/script.lua hook_function_name [early|late]</code></td></tr>
970 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
971 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
972 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
973 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
974 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The optional third argument is supported in 2.3.15 and later</td></tr>
976 Add a hook (at APR_HOOK_MIDDLE) to the translate name phase of
977 request processing. The hook function receives a single
978 argument, the request_rec, and should return a status code,
979 which is either an HTTP error code, or the constants defined
980 in the apache2 module: apache2.OK, apache2.DECLINED, or
983 <p>For those new to hooks, basically each hook will be invoked
984 until one of them returns apache2.OK. If your hook doesn't
985 want to do the translation it should just return
986 apache2.DECLINED. If the request should stop processing, then
987 return apache2.DONE.</p>
991 <pre class="prettyprint lang-config">
993 LuaHookTranslateName /scripts/conf/hooks.lua silly_mapper
997 <pre class="prettyprint lang-lua">
998 -- /scripts/conf/hooks.lua --
1000 function silly_mapper(r)
1001 if r.uri == "/" then
1002 r.filename = "/var/www/home.lua"
1005 return apache2.DECLINED
1011 <div class="note"><h3>Context</h3><p>This directive is not valid in <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code>, <code class="directive"><a href="../mod/core.html#files"><Files></a></code>, or htaccess
1014 <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late"
1015 control when this script runs relative to other modules.</p></div>
1019 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1020 <div class="directive-section"><h2><a name="LuaHookTypeChecker" id="LuaHookTypeChecker">LuaHookTypeChecker</a> <a name="luahooktypechecker" id="luahooktypechecker">Directive</a></h2>
1021 <table class="directive">
1022 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the type_checker phase of request processing</td></tr>
1023 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookTypeChecker /path/to/lua/script.lua hook_function_name</code></td></tr>
1024 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
1025 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
1026 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
1027 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
1029 This directive provides a hook for the type_checker phase of the request processing.
1030 This phase is where requests are assigned a content type and a handler, and thus can
1031 be used to modify the type and handler based on input:
1033 <pre class="prettyprint lang-config">
1034 LuaHookTypeChecker /path/to/lua/script.lua type_checker
1037 <pre class="prettyprint lang-lua">
1038 function type_checker(r)
1039 if r.uri:match("%.to_gif$") then -- match foo.png.to_gif
1040 r.content_type = "image/gif" -- assign it the image/gif type
1041 r.handler = "gifWizard" -- tell the gifWizard module to handle this
1042 r.filename = r.uri:gsub("%.to_gif$", "") -- fix the filename requested
1046 return apache2.DECLINED
1052 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1053 <div class="directive-section"><h2><a name="LuaInherit" id="LuaInherit">LuaInherit</a> <a name="luainherit" id="luainherit">Directive</a></h2>
1054 <table class="directive">
1055 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Controls how parent configuration sections are merged into children</td></tr>
1056 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaInherit none|parent-first|parent-last</code></td></tr>
1057 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaInherit parent-first</code></td></tr>
1058 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
1059 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
1060 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
1061 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
1062 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>2.4.0 and later</td></tr>
1063 </table><p>By default, if LuaHook* directives are used in overlapping
1064 Directory or Location configuration sections, the scripts defined in the
1065 more specific section are run <em>after</em> those defined in the more
1066 generic section (LuaInherit parent-first). You can reverse this order, or
1067 make the parent context not apply at all.</p>
1069 <p> In previous 2.3.x releases, the default was effectively to ignore LuaHook*
1070 directives from parent configuration sections.</p>
1072 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1073 <div class="directive-section"><h2><a name="LuaMapHandler" id="LuaMapHandler">LuaMapHandler</a> <a name="luamaphandler" id="luamaphandler">Directive</a></h2>
1074 <table class="directive">
1075 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Map a path to a lua handler</td></tr>
1076 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaMapHandler uri-pattern /path/to/lua/script.lua [function-name]</code></td></tr>
1077 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
1078 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
1079 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
1080 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
1082 <p>This directive matches a uri pattern to invoke a specific
1083 handler function in a specific file. It uses PCRE regular
1084 expressions to match the uri, and supports interpolating
1085 match groups into both the file path and the function name.
1086 Be careful writing your regular expressions to avoid security
1088 <div class="example"><h3>Examples:</h3><pre class="prettyprint lang-config">
1089 LuaMapHandler /(\w+)/(\w+) /scripts/$1.lua handle_$2
1092 <p>This would match uri's such as /photos/show?id=9
1093 to the file /scripts/photos.lua and invoke the
1094 handler function handle_show on the lua vm after
1095 loading that file.</p>
1097 <pre class="prettyprint lang-config">
1098 LuaMapHandler /bingo /scripts/wombat.lua
1101 <p>This would invoke the "handle" function, which
1102 is the default if no specific function name is
1106 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1107 <div class="directive-section"><h2><a name="LuaPackageCPath" id="LuaPackageCPath">LuaPackageCPath</a> <a name="luapackagecpath" id="luapackagecpath">Directive</a></h2>
1108 <table class="directive">
1109 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.cpath</td></tr>
1110 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackageCPath /path/to/include/?.soa</code></td></tr>
1111 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
1112 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
1113 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
1114 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
1116 <p>Add a path to lua's shared library search path. Follows the same
1117 conventions as lua. This just munges the package.cpath in the
1122 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1123 <div class="directive-section"><h2><a name="LuaPackagePath" id="LuaPackagePath">LuaPackagePath</a> <a name="luapackagepath" id="luapackagepath">Directive</a></h2>
1124 <table class="directive">
1125 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.path</td></tr>
1126 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackagePath /path/to/include/?.lua</code></td></tr>
1127 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
1128 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
1129 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
1130 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
1131 </table><p>Add a path to lua's module search path. Follows the same
1132 conventions as lua. This just munges the package.path in the
1135 <div class="example"><h3>Examples:</h3><pre class="prettyprint lang-config">
1136 LuaPackagePath /scripts/lib/?.lua
1137 LuaPackagePath /scripts/lib/?/init.lua
1142 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1143 <div class="directive-section"><h2><a name="LuaQuickHandler" id="LuaQuickHandler">LuaQuickHandler</a> <a name="luaquickhandler" id="luaquickhandler">Directive</a></h2>
1144 <table class="directive">
1145 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the quick handler of request processing</td></tr>
1146 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaQuickHandler /path/to/script.lua hook_function_name</code></td></tr>
1147 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
1148 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
1149 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
1150 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
1152 <div class="note"><h3>Context</h3><p>This directive is not valid in <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code>, <code class="directive"><a href="../mod/core.html#files"><Files></a></code>, or htaccess
1156 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1157 <div class="directive-section"><h2><a name="LuaRoot" id="LuaRoot">LuaRoot</a> <a name="luaroot" id="luaroot">Directive</a></h2>
1158 <table class="directive">
1159 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Specify the base path for resolving relative paths for mod_lua directives</td></tr>
1160 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaRoot /path/to/a/directory</code></td></tr>
1161 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
1162 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
1163 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
1164 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
1166 <p>Specify the base path which will be used to evaluate all
1167 relative paths within mod_lua. If not specified they
1168 will be resolved relative to the current working directory,
1169 which may not always work well for a server.</p>
1172 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1173 <div class="directive-section"><h2><a name="LuaScope" id="LuaScope">LuaScope</a> <a name="luascope" id="luascope">Directive</a></h2>
1174 <table class="directive">
1175 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>One of once, request, conn, thread -- default is once</td></tr>
1176 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaScope once|request|conn|thread|server [min] [max]</code></td></tr>
1177 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaScope once</code></td></tr>
1178 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
1179 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
1180 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
1181 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
1183 <p>Specify the lifecycle scope of the Lua interpreter which will
1184 be used by handlers in this "Directory." The default is "once"</p>
1187 <dt>once:</dt> <dd>use the interpreter once and throw it away.</dd>
1189 <dt>request:</dt> <dd>use the interpreter to handle anything based on
1190 the same file within this request, which is also
1191 request scoped.</dd>
1193 <dt>conn:</dt> <dd>Same as request but attached to the connection_rec</dd>
1195 <dt>thread:</dt> <dd>Use the interpreter for the lifetime of the thread
1196 handling the request (only available with threaded MPMs).</dd>
1198 <dt>server:</dt> <dd>This one is different than others because the
1199 server scope is quite long lived, and multiple threads
1200 will have the same server_rec. To accommodate this,
1201 server scoped Lua states are stored in an apr
1202 resource list. The <code>min</code> and <code>max</code> arguments
1203 specify the minimum and maximum number of Lua states to keep in the
1207 Generally speaking, the <code>thread</code> and <code>server</code> scopes
1208 execute roughly 2-3 times faster than the rest, because they don't have to
1209 spawn new Lua states on every request (especially with the event MPM, as
1210 even keepalive requests will use a new thread for each request). If you are
1211 satisfied that your scripts will not have problems reusing a state, then
1212 the <code>thread</code> or <code>server</code> scopes should be used for
1213 maximum performance. While the <code>thread</code> scope will provide the
1214 fastest responses, the <code>server</code> scope will use less memory, as
1215 states are pooled, allowing f.x. 1000 threads to share only 100 Lua states,
1216 thus using only 10% of the memory required by the <code>thread</code> scope.
1221 <div class="bottomlang">
1222 <p><span>Available Languages: </span><a href="../en/mod/mod_lua.html" title="English"> en </a> |
1223 <a href="../fr/mod/mod_lua.html" hreflang="fr" rel="alternate" title="Français"> fr </a></p>
1224 </div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
1225 <script type="text/javascript"><!--//--><![CDATA[//><!--
1226 var comments_shortname = 'httpd';
1227 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_lua.html';
1229 if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
1230 d.write('<div id="comments_thread"><\/div>');
1231 var s = d.createElement('script');
1232 s.type = 'text/javascript';
1234 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
1235 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
1238 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
1240 })(window, document);
1241 //--><!]]></script></div><div id="footer">
1242 <p class="apache">Copyright 2012 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
1243 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
1244 if (typeof(prettyPrint) !== 'undefined') {