Mac + nginx + Lua + luasocket + Cjson

Source: Internet
Author: User
Tags lua

1. Lua

Official website http://www.lua.org/Download Source Package
5.1.X version due to use with Nginx
tar xvzf lua-5.1. 5. Tar . gz$ cd LUA-5.1. 5   make do install//must sudo

-------Below is the installation output information------

CD src && mkdir-p/usr/local/bin/usr/local/include/usr/local/lib \
/usr/local/man/man1/usr/local/share/lua/5.1/usr/local/lib/lua/5.1
CD src && install-p-M 0755 Lua Luac/usr/local/bin
CD src && install-p-M 0644 lua.h luaconf.h lualib.h lauxlib.h \
.. /etc/lua.hpp/usr/local/include
CD src && install-p-M 0644 liblua.a/usr/local/lib
CD Doc && install-p-m 0644 lua.1 Luac.1/usr/local/man/man1

This completes the installation of Lua, in general, the installation process will not error
If an error requires an error message to check for lack of environmental dependencies

-------Test----
$ lua
Lua > Print ("Hello, lua")

Exit Control + D

2. Luajit

//Luajit is a JIT-compiled technology that compiles LUA scripts directly into machine code run by the CPU//official websiteHttp://luajit.org/download
//version 2.0 is a stable version$ TarXZVF luajit-2.0.2.Tar. gz$ CD Luajit-2.0.2$ Make$ sudo Make Install--------pay special attention to---------//declare environment variables, the purpose is to compile Nginx source code, tell Nginx where to find Luajit$ Export luajit_lib=/usr/local/luajit/lib$ Export Luajit_inc=/usr/local/luajit/include/luajit-2.0

3. Ngx_devel_kit and Lua-nginx-module

// go directly to GitHub to download the zip file and unzip it tar xvf ngx_devel_kit-master. Zip  tar xvf lua-nginx-module-master. Zip // after editing the Nginx source code, you need to associate the two folders

4. Nginx

  http://nginx.org/download/tar xvf nginx-1.9.  A. Tar . gz$ CD nginx-1.9.  the $ . /configure--add-module=/Absolute path/ngx_devel_kit-master/--add-module=/Absolute path/lua-nginx-module-master/   make makeinstall 

5. Some operations of the Ngnix

// start Nginx$ sudo/usr/local/nginx/sbin/nginx//  reload Nginx$ sudo/usr/local/nginx/ Sbin/nginx-s reload//  Check nginx config file for error $ sudo/usr/local/nginx/sbin/nginx-t/ /  Query Nginx work process number PSgrep  nginx//  forcibly stop, there may be 2 process numbers, Kill The kill -9  process number at the same time

6. Test if the Web service is working

//access to Nginx services$ curl-i"http://localhost:80"------Return the following information normally------HTTP/1.1  $Okserver:nginx/1.9. thedate:wed, OneMay . Geneva: $: $gmtcontent-type:text/htmlcontent-length:612 Last-modified:tue,TenMay .  the: the: +Gmtconnection:keep-Aliveetag:"5731a6bf-264"Accept-ranges:bytes

7. Create the first nginx associated LUA program,/lua-version

//Configuring the/usr/local/nginx/conf/nginx.conf file//here is the code snippet for the configurationServer {Listen the;        server_name localhost; #charset Koi8-R; #access_log logs/Host.access.log Main; Location/{root HTML;        Index index.html index.htm; } Location/lua-Version {Content_by_lua'                ifJit ThenNgx.say (jit.version)ElseNgx.say (_version) End';        }

Location/user-aciton {//How to import Lua scripts
Default_type ' Text/plain ';
Content_by_lua_file/users/admin/developer/workspace/lua/post_user_action.lua;
}

}


$ curl "Http://localhost:80/lua-version"
--------Returns the result-----
Luajit 2.0.4

8. Luasocket

//official websitehttp://luaforge.net/projects/luasocket/$ Tar-ZXVF./luasocket-2.0.2.Tar. gz$ Luasocket-2.0.2$  Make$  Make Install//because the location of the Luasocket module file is not in the System module load path range//so we need to modify Lua's environment variables Lua_path and Lua_cpath//to add the Luasocket location directory to the load path of the system module$ cd$VI. profile$ Export Lua_path=/usr/local/share/lua/5.1/?. lua\;?. lua$ Export Lua_cpath=/usr/local/lib/lua/5.1/socket/?. so\;?. So

9. PCRE

// The system may be prompted to not find Pcre errors when installing Luasocket // as long as you install //  http://www.pcre.orgtar xvzf pcre-8.13. Tar . gz$ CD pcre-8.13$. /makesudomakeinstall

Ten. Cjson

//support UTF-8, UTF-16 and UTF-32 are not supported. #没有任何影响. //support Lua-5.1, Lua-5.2, Luajit$ Tar-ZVXF lua-cjson-2.1.0.Tar. gz$ Make$ sudo  Make Install//Copy the generated cjson.so file to/usr/local/lib/lua/5.1$CPcjson.so/usr/local/lib/lua/5.1/--------make, modify the Makefile file-----##### Build Defaults # # # # #LUA_VERSION=5.1TARGET=Cjson.soprefix=/usr/Local#cflags=-g-wall-pedantic-fno-Inlinecflags=-o3-wall-pedantic-Dndebugcjson_cflags=      -Fpic#cjson_ldflags=     -Sharedcjson_ldflags=-bundle-undefined Dynamic_lookup#lua_include_dir= $ (PREFIX)/Includelua_include_dir= $ (PREFIX)/include/include/luajit-2.0/#LUA_CMODULE_DIR= $ (PREFIX)/lib/lua/$ (lua_version) Lua_cmodule_dir= $ (PREFIX)/Lib#lua_module_dir= $ (PREFIX)/share/lua/$ (lua_version) Lua_module_dir= $ (PREFIX)/share/luajit-2.0.4/Lua_bin_dir= $ (PREFIX)/bin

Mac + nginx + Lua + luasocket + Cjson

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.