详解LUA Web开发服务器配置学习教程


  本文标签:LUA Web开发 服务器

  LUA Web开发服务器配置学习教程是本文要介绍的内容,主要是来学习luaweb开发的内容,有两种方式,一种是apache2.3以上会内置的lua module,大家可以下载apache httpd 2.3.8的代码,在modules目录下有lua这个目录  。

  另外一种是今天要介绍的,使用wsapi方式  。

  我们使用ubuntu服务器,先确保lua5.14以及apache2都安装成功  。

  然后

  1. sudo apt-get install apache2-mpm-worker liblua5.1-0-dev luarocks  
  2. sudo apt-get install libfcgi-dev libapache2-mod-fcgid  
  3. sudo luarocks install wsapi-fcgi 

  然后修改.htaccess或者httpd.conf或者你的vhost配置,添加下面部分  。

  1. Options ExecCGI   
  2. AddHandler fcgid-script .lua   
  3. FCGIWrapper /usr/local/lib/luarocks/bin/wsapi.fcgi .lua 

  要注意的是wsapi.fcgi也许是在不同目录下,用find自己找吧  。

  在var/www下你的站点中新建一个luacgi目录,然后建立两个文件  。

  1. launcher.fcgi:   
  2.  
  3. #!/usr/bin/env lua   
  4.  
  5. require "wsapi.fastcgi"   
  6. require "hello"   
  7. wsapi.fastcgi.run(hello.run)   
  8.  
  9. index.lua:   
  10.  
  11. module(…, package.seeall)   
  12.  
  13. function run(wsapi_env)   
  14.   local headers = { ["Content-type"] = "text/html" }   
  15.  
  16.   local function hello_text()   
  17.     coroutine.yield("<html><body>")   
  18.     coroutine.yield("<p>Hello Wsapi!p>")   
  19.     coroutine.yield("<p>PATH_INFO: " .. wsapi_env.PATH_INFO .. "p>")   
  20.     coroutine.yield("<p>SCRIPT_NAME: " .. wsapi_env.SCRIPT_NAME .. "p>")   
  21.     coroutine.yield("body>html>")   
  22.   end   
  23.  
  24.   return 200, headers, coroutine.wrap(hello_text)   
  25. end 

  然后用chown –R www-data:www-data luacgi修改目录owner  。

  这时候应该就能用xxx.com/luacgi/index.lua访问了  。

  如果你用nginx,也有现成的lua mod可以使用(作者是淘宝的程序员),这里就不多说了  。

  小结:详解LUA Web开发服务器配置学习教程的内容介绍完了,希望通过本文的学习能对你有所帮助!