日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

在CentOS 6.9 x86_64的OpenResty 1.13.6.1上使用LuaRocks示例

發(fā)布時間:2023/11/27 生活经验 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在CentOS 6.9 x86_64的OpenResty 1.13.6.1上使用LuaRocks示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

下面是我閱讀春哥OpenResty官網(wǎng)主頁中“Using LuaRocks”一節(jié)的實操記錄,整理如下。

https://openresty.org/cn/using-luarocks.html

1.在CentOS 6.9 x86_64搭建Lua開發(fā)環(huán)境

詳細過程參見本博博文

http://blog.csdn.net/tao_627/article/details/78925211

2.通過LuaRocks安裝 Lua MD5 庫
在本示例中, 我們將使用Lua MD5 library作為服務器上的一個例子, 所以我們需要通過LuaRocks來安裝它:
luarocks install md5

3.配置我們的OpenResty應用
vim nginx.conf
添加以下內(nèi)容

worker_processes  1;   # we could enlarge this setting on a multi-core machine
user root;
error_log  logs/error.log warn;events {worker_connections  1024;
}http {#must use absolute pathlua_package_path '/root/or_test/conf/using_luarocks/?.lua;;';server {listen       80;server_name  localhost;location = /luarocks {#rewrite_by_lua_file "conf/using_luarocks/foo.lua";content_by_lua 'local foo = require("foo")foo.say("hello, luarocks!")--ngx.say("Hello world!")';}}
}

我們希望最終的目錄結(jié)構(gòu)如下


創(chuàng)建與conf下面的using_luarocks子文件夾存放lua文件
mkdir -p /root/or_test/conf/using_luarocks
存入foo.lua

module("foo", package.seeall)local bar = require "bar"ngx.say("bar loaded")function say (var)bar.say(var)
end
存入bar.lua
module("bar", package.seeall)local rocks = require "luarocks.loader"
local md5 = require "md5"ngx.say("rocks and md5 loaded")function say (a)ngx.say(md5.sumhexa(a))
end

4.開啟Nginx服務
首先測試配置文件合法性
nginx -p ~/or_test -c ~/or_test/conf/using_luarocks.conf -t
重啟OpenResty服務
nginx -p ~/or_test -c ~/or_test/conf/using_luarocks.conf -s reload
查看進程是否正常
ps auxf | grep nginx
查看端口是否啟動
netstat -ntlp


5.測試我們的應用
現(xiàn)在我們通過curl 工具或者任意兼容HTTP協(xié)議的瀏覽器測試我們的應用:
curl -v http://localhost/luarocks
我們在第一次運行的時候得到以下的內(nèi)容:
rocks and md5 loaded
bar loaded
85e73df5c41378f830c031b81e4453d2


第二次運行的時候得到以下內(nèi)容:
85e73df5c41378f830c031b81e4453d2


6.基準測試
現(xiàn)在,讓我們來做一些基準測試吧:
ab -c10 -n50000 http://127.0.0.1/luarocks
測試在是我的CentOS 6.9 x86_64虛擬機上進行的, 下面是測試中產(chǎn)生的數(shù)據(jù)



7.特殊說明
這里OpenResty默認包含了LuaJIT,系統(tǒng)中沒有完整的lua程序,我使用源碼安裝了完整的lua,并繼續(xù)安裝了模塊管理工具LuaRocks,
使用LuaRocks去安裝其它lua相關(guān)的模塊(OpenResty中沒有包含的),并通過在nginx.conf中引用這些lua腳本來實現(xiàn)一些業(yè)務需求,比如這里的md5模塊。這個思路是可行的。


8.參考文獻
[1].https://openresty.org/cn/using-luarocks.html

總結(jié)

以上是生活随笔為你收集整理的在CentOS 6.9 x86_64的OpenResty 1.13.6.1上使用LuaRocks示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。