The power of gsung and the high performance of lua are really a good combination. when it comes together, it will be invincible. Configure nginx to support lua, which is implemented by an nginx module. module address: ingress
The power of gsung and the high performance of lua are really a good combination. when it comes together, it will be invincible.
The following describes how to configure nginx to support lua through an nginx module,
Module address: https://github.com/chaoslawful/lua-nginx-module
Download link: https://github.com/chaoslawful/lua-nginx-module/archive/v0.8.10.tar.gz
1. download and decompress the source code
A. nginx source code:
|
[Root @ localhost ~] # Wget http://nginx.org/download/nginx-1.4.2.tar.gz?root@localhost ~] # Tar zxvf nginx-1.4.2.tar.gz |
B. lua module
|
[Root @ localhost ~] # Wget-O lua-nginx-module-0.8.10.tar.gz ~] # Tar zxvf lua-nginx-module-0.8.10.tar.gz |
C. luajit (lua instant compiler)
|
[Root @ localhost ~] # Wget http://luajit.org/download/luajit-2.0.2.tar.gz?root@localhost ~] # Tar zxvf LuaJIT-2.0.2.tar.gz |
D. ngx_devel_kit (nginx Development Kit)
|
[Root @ localhost ~] # Wget-O ngx_devel_kit-0.2.18.tar.gz https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz?root@localhost ~] # Tar zxvf ngx_devel_kit-0.2.18.tar.gz |
2. install luajit
|
[Root @ localhost ~] # Make [root @ localhost ~] # Make install |
3. install nginx
Method a. Use the luajit instant compiler
|
[Root @ localhost nginx-1.4.1] # export LUAJIT_LIB =/usr/local/lib [root @ localhost nginx-1.4.1] # export LUAJIT_INC =/usr/local/include/luajit-2.0 [root @ localhost nginx-1.4.1] #. /configure \ -- prefix =/usr/local/nginx-1.4.1 \ -- with-http_stub_status_module \ -- add-module = .. /lua-nginx-module-0.8.9 \ -- add-module = .. /ngx_devel_kit-0.2.18 [root @ localhost nginx-1.4.1] # make-j 4 [root @ localhost nginx-1.4.1] # make inst All [root @ localhost ~] # Echo '/usr/local/lib'>/etc/ld. so. conf. d/lua. conf [root @ localhost ~] # Ldconfig |
Method B. use the lua compiler
|
[Root @ localhost nginx-1.4.1] # export LUA_LIB =/usr/lib64 [root @ localhost nginx-1.4.1] # export LUA_INC =/usr/include [root @ localhost nginx-1.4.1] #. /configure \ -- prefix =/usr/local/nginx-1.4.1 \ -- with-http_stub_status_module \ -- add-module = .. /lua-nginx-module-0.8.9 \ -- add-module = .. /ngx_devel_kit-0.2.18 [root @ localhost nginx-1.4.1] # make-j 4 [root @ localhost nginx-1.4.1] # make install |
Note: To enable nginx to support lua, you can use either the luajit instant compiler or the lua compiler. We recommend that you use luajit because of its high efficiency.
4. verify installation
When using the lua compiler, the following information is displayed:
|
[Root @ localhost ~] # Lsof-p 3359 | grep-I luang1_3359 root mem REG 8, 3183920394551/usr/lib64/liblua-5.1.so |
When you use the luajit instant compiler, the following information is displayed:
|
[Root @ localhost ~] # Lsof-p 13177 | grep-I luang1_13177 root mem REG 452024 405089/usr/local/lib/libluajit-5.1.so.2.0.2 |
5. verify configuration commands and outputs
Modify the nginx. conf configuration file and add the following command:
|
Location/{content_by_lua 'ngx. say ("hello world! ")';} |
Restart nginx and use curl for testing
|
[Root @ localhost ~] # Curl-I localhostHTTP/1.1 200 OKServer: nginx/1.4.1Date: Tue, 24 Sep 2013 23:23:58 GMTContent-Type: application/octet-streamTransfer-Encoding: chunkedConnection: keep-alivehello world! |
6. success
For more instructions available, refer to: http://wiki.nginx.org/HttpLuaModule
This article is from the "good luck" blog, please be sure to keep this source http://haoyun.blog.51cto.com/2038762/1301257