日期:2014-05-16  浏览次数:21301 次

windows 上 搭建 apache + lua 运行环境

为了搭建apache - lua 好不容易从网上下载到了 mod_lua.so 的windows版本
但是始终搞不成,找了N天才发现 这玩意要 apache 2.3+的版本支持, 见此处?


但是 apache官方并无 2.3+以上版本 windows 的版本下载,终于找到一个位置
http://www.apachelounge.com/download/

?

下载了 32位的 apache 2.4的版本,其中便内置了? mod_lua.so o(∩_∩)o 哈哈

?

在 httpd.conf中开启这个模块,然后新增一行 AddHandler lua-script .lua

?

在 htdocs下新增 2个lua脚本文件来进行测试即可

?

info.lua

-- Extend tostring to report function type (C or Lua)
do
  local type, tostr = type, tostring
  function tostring(obj)
    local type, val = type(obj), tostr(obj)
    if type == "function" then
      type = pcall(coroutine.create, obj) and "Lua " or "C " -- coroutines cannot start at a C function
      return type .. val
    else
      return val
    end
  end
end

local safe_replacements = {
  ["<"] = "&lt;",
  [">"] = "&gt;",
  ["&"] ="&amp;",
}
local function safestring(...)
  return tostring(...):gsub("[<>&]", safe_replacements):gsub("\n", "<br/>\n")
end
local function emstring(...)
  return "&quot;<em>".. safestring(...) .."</em>&quot;"
end

local function print_info(info)
  print [[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>mod_lua info</title>
    <style type="text/css">
      body {
        background-color: #eef;
	color: black;
	font-family: sans-serif;
      }
      table {
        border-collapse: collapse;
	text-align: left;
	margin-left: auto;
	margin-right: auto;
      }
      table.head th {
        vertical-align: middle;
	background-color: #99c;
      }
      div.center {
        text-align: center;
      }
      h1 {
        margin: 0;
	padding: 0.3em 0;
      }
      td, th {
        border: 1px black solid;
	vertical-align: baseline;
	font-size: 75%;
      }
      th {
        background-color: #ccf;
      }
      td {
        background-color: #ccc;
      }
      ul {
        list-style: square;
	margin: 0;
	padding-left: 2em;
      }
    </style>
  </head>
  <body>
    <div class="center">
      <table class="head" width="600">
        <tr> <th><h1>mod_lua</h1></th> </tr>
      </table>
]]
  for group, settings in pairs(info) do
    print('<h2><a name="'.. group:gsub("[^a-zA-Z]", "") ..'">'.. group .. "</a></h2>")
    print [[
      <table width="600">
]]
    for key, value in pairs(settings) do
      print("<tr> <th>".. key .."</th> <td>".. value .."</td> </tr>\n")
    end
    print "</table>\n"
  end
  print [[
    </div>
  </body>
</html>
]]
end

local function compile_info(req)
  local info = {}
  do -- Lua compile options
    local dump = string.dump(function() end)
    local gc_pause = collectgarbage("setpause", 1); collectgarbage("setpause", gc_pause)
    local gc_stepmul = collectgarbage("setstepmul", 2); collectgarbage("setstepmul", gc_stepmul)
    info["Lua configuration"] = {
      -- Bytecode header is undocumented, see luaU_header in lundump.c
      Version = ("%i.%i"):format(math.floor(dump:byte(5) / 16), dump:byte(5) % 16),
      Endianness = dump:byte(7) == 1 and "little" or "big",
      int = dump:byte(8)*8 .. " bit integer",
      size_t = dump:byte(9)*8 .. " bit integer",
      ["VM instruction"] = dump:byte(10)*8 .. " bit integer",
      Number = dump:byte(11)*8 .. " bit " .. (dump:byte(12) == 1 and "integer" or "float"),
      -- package.config is undocumented, see luaopen_package in loadlib.c
      ["Path seperator"] = safestring(package.config:sub(1,1)),
      ["Lua package path"] = safestring(package.path:gsub(package.config:sub(3,3), "\n")),
      ["C package path"] = safestring(pac