设为首页 收藏本站
查看: 556|回复: 0

[经验分享] windows 上 搭建 apache + lua 运行环境

[复制链接]

尚未签到

发表于 2017-1-6 12:22:26 | 显示全部楼层 |阅读模式
  为了搭建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(package.cpath:gsub(package.config:sub(3,3), "\n")),
-- Garbage collection values _are_ documented :)
["GC count"] = ("%.0f bytes"):format(collectgarbage"count" * 1024),
["GC pause"] = ("%.0f%%"):format(gc_pause),
["GC step multiplier"] = ("%.0f%%"):format(gc_stepmul),
}
end
do -- Globals
local g = {}
for key, value in pairs(getfenv(0)) do
local typev = type(value)
local str
if typev == "table" then
str = safestring(value)
if value ~= getfenv(0) then -- don't recursively follow _G
str = str .. "<ul>"
for field, v in pairs(value) do
str = str .. "<li>" .. safestring(field) .. " ("
if type(v) == "string" then
str = str .. emstring(v)
else
str = str .. safestring(v)
end
str = str .. ")</li>"
end
str = str .. "</ul>"
end
elseif typev == "string" then
str = emstring(value)
else
str = safestring(value)
end
g[safestring(key)] = str
end
info.Globals = g
end
do -- Request object
local rinfo = {}
for _, field in pairs{"puts", "write", "document_root", "parseargs", "parsebody", "debug", "info", "notice",
"warn", "err", "crit", "alert", "emerg", "add_output_filter", "assbackwards", "status", "protocol", "range",
"content_type", "content_encoding", "ap_auth_type", "unparsed_uri", "user", "filename", "canonical_filename",
"path_info", "args", "hostname", "uri", "the_request", "method", "headers_in", "headers_out"} do
local value = req[field]
if type(value) == "userdata" and apr_table and apr_table.pairs then
local list = "<ul>"
for key, value in apr_table.pairs(value) do
list = list .. "<li>" .. safestring(key) .. " (" .. emstring(value) .. ")</li>"
end
rinfo[field] = tostring(req[field]) .. list .. "</ul>"
elseif type(value) == "string" then
rinfo[field] = emstring(req[field])
else
rinfo[field] = safestring(req[field])
end
end
info.Request = rinfo
end
do -- Arguments (query string)
local args = req:parseargs()
local args_clean = {}
for key, value in pairs(args) do
args_clean[safestring(key)] = emstring(value)
end
if next(args_clean) then
info["Query string"] = args_clean
end
end
return info
end
function handle(r)
-- setup the environment
r.content_type = "text/html"
r.headers_out["X-Powered-By"] = "mod_lua; " .. _VERSION
print = function(s) return r:write(tostring(s)) end
-- run the main script
local info = compile_info(r)
print_info(info)
-- finish
return apache2.OK
end

  hello_world.lua

require "apache2"
function handle(r)
r.content_type = "text/html"
r:write "Hello World from <strong>mod_lua</strong>."
return apache2.OK
end

  如果要配置 apache2.4 + php 请参见我上一个帖子

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-324738-1-1.html 上篇帖子: Apache服务器四个功能 (转) 下篇帖子: Apache Mina 2 文档翻译
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表