{"id":230137,"date":"2023-12-25T15:31:22","date_gmt":"2023-12-25T07:31:22","guid":{"rendered":"https:\/\/www.idc.net\/help\/230137\/"},"modified":"2023-12-25T15:31:22","modified_gmt":"2023-12-25T07:31:22","slug":"apache%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e4%bd%bf%e7%94%a8mod_lua%e8%ae%be%e7%bd%aeapache","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/230137\/","title":{"rendered":"Apache\u65b0\u624b\u6559\u7a0b\uff1a\u4f7f\u7528mod_lua\u8bbe\u7f6eApache"},"content":{"rendered":"<h2 id=\"apache%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e4%bd%bf%e7%94%a8mod_lua%e8%ae%be%e7%bd%aeapache-HTtAUOTfHM\">Apache\u65b0\u624b\u6559\u7a0b\uff1a\u4f7f\u7528mod_lua\u8bbe\u7f6eApache<\/h2>\n<p>Apache\u662f\u4e00\u6b3e\u5e7f\u6cdb\u4f7f\u7528\u7684\u5f00\u6e90Web\u670d\u52a1\u5668\u8f6f\u4ef6\uff0c\u5b83\u53ef\u4ee5\u5728\u5404\u79cd\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u7075\u6d3b\u7684\u914d\u7f6e\u9009\u9879\u3002\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528mod_lua\u6a21\u5757\u6765\u8bbe\u7f6eApache\u670d\u52a1\u5668\u3002<\/p>\n<h3 id=\"%e4%bb%80%e4%b9%88%e6%98%afmod_lua%ef%bc%9f-HTtAUOTfHM\">\u4ec0\u4e48\u662fmod_lua\uff1f<\/h3>\n<p>mod_lua\u662fApache\u7684\u4e00\u4e2a\u6a21\u5757\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4f7f\u7528Lua\u811a\u672c\u8bed\u8a00\u6765\u6269\u5c55\u548c\u5b9a\u5236Apache\u670d\u52a1\u5668\u7684\u529f\u80fd\u3002Lua\u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u811a\u672c\u8bed\u8a00\uff0c\u5177\u6709\u7b80\u5355\u6613\u5b66\u3001\u9ad8\u6548\u7075\u6d3b\u7684\u7279\u70b9\uff0c\u975e\u5e38\u9002\u5408\u7528\u4e8e\u7f16\u5199Web\u670d\u52a1\u5668\u7684\u6269\u5c55\u6a21\u5757\u3002<\/p>\n<h3 id=\"%e5%ae%89%e8%a3%85mod_lua%e6%a8%a1%e5%9d%97-HTtAUOTfHM\">\u5b89\u88c5mod_lua\u6a21\u5757<\/h3>\n<p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Apache\u670d\u52a1\u5668\u548cLua\u89e3\u91ca\u5668\u3002\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5728Ubuntu\u4e0a\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<pre><code>sudo apt-get install apache2 lua5.3 libapache2-mod-lua<\/code><\/pre>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u9700\u8981\u542f\u7528mod_lua\u6a21\u5757\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u7528\uff1a<\/p>\n<pre><code>sudo a2enmod lua<\/code><\/pre>\n<p>\u91cd\u542fApache\u670d\u52a1\u5668\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>sudo service apache2 restart<\/code><\/pre>\n<h3 id=\"%e7%bc%96%e5%86%99lua%e8%84%9a%e6%9c%ac-HTtAUOTfHM\">\u7f16\u5199Lua\u811a\u672c<\/h3>\n<p>\u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199Lua\u811a\u672c\u6765\u6269\u5c55Apache\u670d\u52a1\u5668\u7684\u529f\u80fd\u4e86\u3002\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u4f8b\u5982<strong>hello.lua<\/strong>\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code>function handle(r)\n    r.content_type = \"text\/html\"\n    r:puts(\"&lt;h1&gt;Hello, mod_lua!&lt;\/h1&gt;\")\n    return apache2.OK\nend<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<strong>handle<\/strong>\u7684\u51fd\u6570\uff0c\u5b83\u63a5\u6536\u4e00\u4e2a\u8bf7\u6c42\u5bf9\u8c61<strong>r<\/strong>\u4f5c\u4e3a\u53c2\u6570\u3002\u51fd\u6570\u8bbe\u7f6e\u4e86\u54cd\u5e94\u7684\u5185\u5bb9\u7c7b\u578b\u4e3a\"text\/html\"\uff0c\u5e76\u8f93\u51fa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684HTML\u6807\u9898\u3002\u6700\u540e\uff0c\u51fd\u6570\u8fd4\u56de\u4e86\u4e00\u4e2a\u72b6\u6001\u7801<strong>apache2.OK<\/strong>\uff0c\u8868\u793a\u5904\u7406\u6210\u529f\u3002<\/p>\n<h3 id=\"%e9%85%8d%e7%bd%aeapache%e6%9c%8d%e5%8a%a1%e5%99%a8-HTtAUOTfHM\">\u914d\u7f6eApache\u670d\u52a1\u5668<\/h3>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u914d\u7f6eApache\u670d\u52a1\u5668\u4ee5\u4f7f\u7528\u6211\u4eec\u7f16\u5199\u7684Lua\u811a\u672c\u3002\u6253\u5f00Apache\u7684\u914d\u7f6e\u6587\u4ef6<strong>\/etc\/apache2\/apache2.conf<\/strong>\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code>&lt;Location \/lua&gt;\n    SetHandler lua-script\n    LuaHandler hello.handle\n&lt;\/Location&gt;<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u8bf7\u6c42\u8def\u5f84\u4e3a<strong>\/lua<\/strong>\u7684\u8bf7\u6c42\u4ea4\u7ed9mod_lua\u6a21\u5757\u5904\u7406\uff0c\u5e76\u4f7f\u7528\u6211\u4eec\u7f16\u5199\u7684<strong>hello.handle<\/strong>\u51fd\u6570\u6765\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<p>\u4fdd\u5b58\u5e76\u5173\u95ed\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u91cd\u542fApache\u670d\u52a1\u5668\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\uff1a<\/p>\n<pre><code>sudo service apache2 restart<\/code><\/pre>\n<h3 id=\"%e6%b5%8b%e8%af%95-HTtAUOTfHM\">\u6d4b\u8bd5<\/h3>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee<strong>http:\/\/localhost\/lua<\/strong>\u6765\u6d4b\u8bd5\u6211\u4eec\u7684Lua\u811a\u672c\u662f\u5426\u751f\u6548\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u4f60\u5c06\u5728\u6d4f\u89c8\u5668\u4e2d\u770b\u5230\u4e00\u4e2a\u5e26\u6709\u6807\u9898\"Hello, mod_lua!\"\u7684\u9875\u9762\u3002<\/p>\n<h3 id=\"%e6%80%bb%e7%bb%93-HTtAUOTfHM\">\u603b\u7ed3<\/h3>\n<p>\u901a\u8fc7\u4f7f\u7528mod_lua\u6a21\u5757\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Lua\u811a\u672c\u6765\u6269\u5c55\u548c\u5b9a\u5236Apache\u670d\u52a1\u5668\u7684\u529f\u80fd\u3002\u672c\u6559\u7a0b\u4ecb\u7ecd\u4e86\u5b89\u88c5mod_lua\u6a21\u5757\u3001\u7f16\u5199Lua\u811a\u672c\u4ee5\u53ca\u914d\u7f6eApache\u670d\u52a1\u5668\u7684\u6b65\u9aa4\u3002\u5e0c\u671b\u8fd9\u4e2a\u6559\u7a0b\u5bf9\u4e8e\u60f3\u8981\u6df1\u5165\u4e86\u89e3Apache\u670d\u52a1\u5668\u7684\u65b0\u624b\u6765\u8bf4\u662f\u6709\u5e2e\u52a9\u7684\u3002<\/p>\n<p>\u9999\u6e2f\u670d\u52a1\u5668\u9996\u9009\u540e\u6d6a\u4e91\uff1a<a href=\"https:\/\/idc.net\">https:\/\/idc.net<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache\u65b0\u624b\u6559\u7a0b\uff1a\u4f7f\u7528mod_lua\u8bbe\u7f6eApache Apache\u662f\u4e00\u6b3e\u5e7f\u6cdb\u4f7f\u7528\u7684\u5f00\u6e90Web\u670d\u52a1\u5668\u8f6f\u4ef6\uff0c\u5b83 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[],"class_list":["post-230137","post","type-post","status-publish","format-standard","hentry","category-apache"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/230137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=230137"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/230137\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=230137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=230137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=230137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}