{"id":41484,"date":"2024-10-01T19:56:30","date_gmt":"2024-10-01T11:56:30","guid":{"rendered":"https:\/\/server.hk\/cnblog\/41484\/"},"modified":"2024-10-01T19:56:30","modified_gmt":"2024-10-01T11:56:30","slug":"apache%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e8%a8%ad%e5%ae%9aapache%e8%88%87mod_lua","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/41484\/","title":{"rendered":"Apache\u65b0\u624b\u6559\u7a0b\uff1a\u8a2d\u5b9aApache\u8207mod_lua"},"content":{"rendered":"<h1 id=\"apache%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e8%a8%ad%e5%ae%9aapache%e8%88%87mod_lua-GXVMQllZBl\">Apache\u65b0\u624b\u6559\u7a0b\uff1a\u8a2d\u5b9aApache\u8207mod_lua<\/h1>\n<p>Apache HTTP Server\uff08\u7c21\u7a31Apache\uff09\u662f\u4e00\u6b3e\u5ee3\u6cdb\u4f7f\u7528\u7684\u958b\u6e90\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u56e0\u5176\u7a69\u5b9a\u6027\u548c\u9748\u6d3b\u6027\u800c\u53d7\u5230\u8a31\u591a\u958b\u767c\u8005\u7684\u9752\u775e\u3002\u96a8\u8457\u7db2\u9801\u61c9\u7528\u7a0b\u5f0f\u7684\u9700\u6c42\u4e0d\u65b7\u589e\u52a0\uff0cApache\u4e5f\u4e0d\u65b7\u9032\u5316\uff0c\u63d0\u4f9b\u4e86\u8a31\u591a\u64f4\u5c55\u529f\u80fd\uff0c\u5176\u4e2d\u4e4b\u4e00\u4fbf\u662fmod_lua\u6a21\u7d44\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u8a2d\u5b9aApache\u8207mod_lua\uff0c\u5e6b\u52a9\u65b0\u624b\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afmod_lua%ef%bc%9f-GXVMQllZBl\">\u4ec0\u9ebc\u662fmod_lua\uff1f<\/h2>\n<p>mod_lua\u662f\u4e00\u500bApache\u6a21\u7d44\uff0c\u5141\u8a31\u7528\u6236\u4f7f\u7528Lua\u8a9e\u8a00\u4f86\u7de8\u5beb\u4f3a\u670d\u5668\u7aef\u7684\u8173\u672c\u3002Lua\u662f\u4e00\u7a2e\u8f15\u91cf\u7d1a\u7684\u8173\u672c\u8a9e\u8a00\uff0c\u56e0\u5176\u7c21\u6f54\u548c\u9ad8\u6548\u800c\u53d7\u5230\u5ee3\u6cdb\u4f7f\u7528\u3002\u901a\u904emod_lua\uff0c\u7528\u6236\u53ef\u4ee5\u5728Apache\u4f3a\u670d\u5668\u4e0a\u57f7\u884cLua\u8173\u672c\uff0c\u5f9e\u800c\u5be6\u73fe\u66f4\u9748\u6d3b\u7684\u7db2\u9801\u8655\u7406\u548c\u6578\u64da\u8655\u7406\u529f\u80fd\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9dapache%e8%88%87mod_lua-GXVMQllZBl\">\u5b89\u88ddApache\u8207mod_lua<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u78ba\u4fdd\u4f60\u7684\u4f3a\u670d\u5668\u4e0a\u5df2\u7d93\u5b89\u88dd\u4e86Apache\u3002\u4ee5\u4e0b\u662f\u5b89\u88ddApache\u548cmod_lua\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e5%ae%89%e8%a3%9dapache-GXVMQllZBl\">1. \u5b89\u88ddApache<\/h3>\n<pre><code>sudo apt update\nsudo apt install apache2\n<\/code><\/pre>\n<h3 id=\"2-%e5%ae%89%e8%a3%9dmod_lua-GXVMQllZBl\">2. \u5b89\u88ddmod_lua<\/h3>\n<p>\u5728\u5b89\u88ddmod_lua\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u78ba\u4fddApache\u7684\u958b\u767c\u5305\u5df2\u7d93\u5b89\u88dd\u3002\u7136\u5f8c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88ddmod_lua\uff1a<\/p>\n<pre><code>sudo apt install libapache2-mod-lua\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u7528mod_lua\u6a21\u7d44\uff1a<\/p>\n<pre><code>sudo a2enmod lua\n<\/code><\/pre>\n<h3 id=\"3-%e9%87%8d%e6%96%b0%e5%95%9f%e5%8b%95apache-GXVMQllZBl\">3. \u91cd\u65b0\u555f\u52d5Apache<\/h3>\n<p>\u70ba\u4e86\u4f7f\u66f4\u6539\u751f\u6548\uff0c\u8acb\u91cd\u65b0\u555f\u52d5Apache\u4f3a\u670d\u5668\uff1a<\/p>\n<pre><code>sudo systemctl restart apache2\n<\/code><\/pre>\n<h2 id=\"%e8%a8%ad%e5%ae%9aapache%e4%bb%a5%e4%bd%bf%e7%94%a8mod_lua-GXVMQllZBl\">\u8a2d\u5b9aApache\u4ee5\u4f7f\u7528mod_lua<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u8a2d\u5b9aApache\u4ee5\u4f7f\u7528mod_lua\u3002\u9019\u901a\u5e38\u6d89\u53ca\u5230\u7de8\u8f2fApache\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<h3 id=\"1-%e7%b7%a8%e8%bc%afapache%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-GXVMQllZBl\">1. \u7de8\u8f2fApache\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u4f7f\u7528\u6587\u672c\u7de8\u8f2f\u5668\u6253\u958bApache\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u5e38\u4f4d\u65bc\/etc\/apache2\/sites-available\/000-default.conf\uff1a<\/p>\n<pre><code>sudo nano \/etc\/apache2\/sites-available\/000-default.conf\n<\/code><\/pre>\n<h3 id=\"2-%e6%b7%bb%e5%8a%a0lua%e8%85%b3%e6%9c%ac%e8%99%95%e7%90%86-GXVMQllZBl\">2. \u6dfb\u52a0Lua\u8173\u672c\u8655\u7406<\/h3>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u78bc\u4ee5\u8a2d\u7f6eLua\u8173\u672c\u7684\u8655\u7406\uff1a<\/p>\n<pre><code>&lt;Location \/lua&gt;\n    LuaHandler my_lua_script.handler\n&lt;\/Location&gt;\n<\/code><\/pre>\n<p>\u9019\u88e1\u7684my_lua_script.handler\u662f\u4f60\u5c07\u8981\u5275\u5efa\u7684Lua\u8173\u672c\u7684\u8655\u7406\u51fd\u6578\u3002<\/p>\n<h3 id=\"3-%e5%89%b5%e5%bb%balua%e8%85%b3%e6%9c%ac-GXVMQllZBl\">3. \u5275\u5efaLua\u8173\u672c<\/h3>\n<p>\u5728\u4f3a\u670d\u5668\u4e0a\u5275\u5efa\u4e00\u500bLua\u8173\u672c\u6587\u4ef6\uff0c\u4f8b\u5982my_lua_script.lua\uff0c\u4e26\u5c07\u5176\u653e\u7f6e\u5728\u9069\u7576\u7684\u76ee\u9304\u4e2d\uff08\u5982\/var\/www\/html\/\uff09\uff1a<\/p>\n<pre><code>sudo nano \/var\/www\/html\/my_lua_script.lua\n<\/code><\/pre>\n<p>\u5728\u8a72\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u7c21\u55ae\u7684Lua\u4ee3\u78bc\uff1a<\/p>\n<pre><code>function handler(r)\n    r:puts(\"Hello from Lua!\")\n    return apache2.OK\nend\n<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e8%a8%ad%e5%ae%9a-GXVMQllZBl\">\u6e2c\u8a66\u8a2d\u5b9a<\/h2>\n<p>\u5b8c\u6210\u4e0a\u8ff0\u6b65\u9a5f\u5f8c\uff0c\u6253\u958b\u700f\u89bd\u5668\u4e26\u8a2a\u554fhttp:\/\/your-server-ip\/lua\uff0c\u61c9\u8a72\u80fd\u770b\u5230\u201cHello from Lua!\u201d\u7684\u8a0a\u606f\uff0c\u9019\u8868\u793amod_lua\u5df2\u6210\u529f\u904b\u884c\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-GXVMQllZBl\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5b89\u88dd\u548c\u8a2d\u5b9aApache\u8207mod_lua\uff0c\u4e26\u63d0\u4f9b\u4e86\u7c21\u55ae\u7684Lua\u8173\u672c\u793a\u4f8b\u3002\u901a\u904e\u9019\u4e9b\u6b65\u9a5f\uff0c\u65b0\u624b\u53ef\u4ee5\u5feb\u901f\u4e0a\u624bApache\u7684\u64f4\u5c55\u529f\u80fd\uff0c\u9032\u4e00\u6b65\u63d0\u5347\u7db2\u9801\u61c9\u7528\u7684\u9748\u6d3b\u6027\u548c\u6027\u80fd\u3002\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u4f86\u904b\u884c\u4f60\u7684Apache\u4f3a\u670d\u5668\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u8a2d\u5b9aApache\u4f3a\u670d\u5668\u8207mod_lua\uff0c\u9069\u5408\u65b0\u624b\u7684\u8a73\u7d30\u6559\u7a0b\uff0c\u52a9\u4f60\u8f15\u9b06\u638c\u63e1\u7db2\u9801\u4f3a\u670d\u5668\u914d\u7f6e\u6280\u5de7\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-41484","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/41484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=41484"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/41484\/revisions"}],"predecessor-version":[{"id":41485,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/41484\/revisions\/41485"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=41484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=41484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=41484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}