開始學習OpenResty
OpenResty下載地址
https://openresty.org/download/ngx_openresty-1.9.3.2.tar.gz
Nginx增加模組需要重新編譯.
OpenResty 將很多常用的模組,包括LUA支援,cjson等,直接打包在一起.
使用起來非常的方便.隨手用的模組都有,也免去了重新編譯的煩惱.
安裝:
useradd -m nginx
加壓檔案,建立目標資料夾OpenResty
[nginx@localhost~]$tar -zxvf ngx_openresty-1.9.3.2.tar.gz
[nginx@localhost~]$mkdir OpenResty
[nginx@localhost~]$cd ngx_openresty-1.9.3.2
然後執行
./configure --prefix=/home/nginx/OpenResty
make -j `cat /proc/cpuinfo | grep processor| wc -l`
make install
安裝結束.可以看到Nginx和相關模組已經安裝完成.
[nginx@localhost~]$ls OpenResty/
bin luajit lualib nginx
修改Nginx配置檔案,通過Lua訪問MySQL
vim /home/nginx/OpenResty/nginx/conf/nginx.conf
建立/home/nginx/lua_mysql.lua檔案,增加lua邏輯
測試結果:
[nginx@localhost~]$curl http://172.16.1.78:8088/lua_mysql
[{"name":"s1","id":1},{"name":"s2","id":2}]
他這個db:query是冒號..
下面這種用法,比較有意思.
參考:
https://github.com/openresty/lua-resty-mysql
http://openresty.org/cn/
http://blog.csdn.net/qinyushuang/article/details/43950497
http://www.tuicool.com/articles/iayuqi
https://openresty.org/download/ngx_openresty-1.9.3.2.tar.gz
Nginx增加模組需要重新編譯.
OpenResty 將很多常用的模組,包括LUA支援,cjson等,直接打包在一起.
使用起來非常的方便.隨手用的模組都有,也免去了重新編譯的煩惱.
安裝:
useradd -m nginx
加壓檔案,建立目標資料夾OpenResty
[nginx@localhost~]$tar -zxvf ngx_openresty-1.9.3.2.tar.gz
[nginx@localhost~]$mkdir OpenResty
[nginx@localhost~]$cd ngx_openresty-1.9.3.2
然後執行
./configure --prefix=/home/nginx/OpenResty
make -j `cat /proc/cpuinfo | grep processor| wc -l`
make install
[nginx@localhost~]$ls OpenResty/
bin luajit lualib nginx
vim /home/nginx/OpenResty/nginx/conf/nginx.conf
建立/home/nginx/lua_mysql.lua檔案,增加lua邏輯
- local mysql=require "resty.mysql"
- local cjson=require "cjson"
- local db,_=mysql:new()
- db:set_timeout(1000)
- local ok,err,errno,sqlstate=db:connect{
- host="127.0.0.1",
- port=3306,
- database="mvbox",
- user="xx",
- password="xx"
- }
- if not ok then
- ngx.say("failed to connect:",err,",",errno,",",sqlstate)
- return
- end
- db:query("drop table if exists t1")
- db:query("create table t1(id int primary key auto_increment,name varchar(20))")
- db:query("insert into t1(name) values(\'s1\')")
- db:query("insert into t1(name) values(\'s2\')")
- local res,err,errno,sqlstate=db:query("select * from t1")
- if not res then
- ngx.say("bad result:",err,",",errno,",",sqlstate)
- return
- end
- ngx.say(cjson.encode(res))
- db:close()
測試結果:
[nginx@localhost~]$curl http://172.16.1.78:8088/lua_mysql
[{"name":"s1","id":1},{"name":"s2","id":2}]
他這個db:query是冒號..
下面這種用法,比較有意思.
參考:
https://github.com/openresty/lua-resty-mysql
http://openresty.org/cn/
http://blog.csdn.net/qinyushuang/article/details/43950497
http://www.tuicool.com/articles/iayuqi
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29254281/viewspace-1849844/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 開始學習啦
- 開始學習 Backbone
- 今天開始學習 goGo
- 開始學習Python!Python
- 開始重新學習JAVAJava
- 開始學習Mysql了MySql
- 學習openresty時,nginx的一個坑RESTNginx
- OpenResty學習筆記03:再探WAFREST筆記
- 今天開始學習PYTHONPython
- 從頭開始學習VuexVue
- 從零開始學習KafkaKafka
- 被迫開始學習Typescript —— classTypeScript
- 從零開始學習機器學習機器學習
- 開始學習 PixiJSJS
- 開始學習電商實戰
- 從零開始學習laravelLaravel
- 被迫開始學習Typescript —— interfaceTypeScript
- go學習--->開始編碼Go
- Java Web學習之旅開始JavaWeb
- 開始學習Functional ProgrammingFunction
- SQL Server開始學習感受SQLServer
- 我想開始學習javaJava
- 開始我的學習之旅。。。。
- 開始學習除錯MySQL除錯MySql
- 從0開始學習java,應該從那塊開始學起?Java
- 如何開始學習Go語言Go
- 從0開始學習Webpack(一)Web
- 學習小程式從“你”開始
- 開始學習使用Node.jsNode.js
- 明天開始系統學習oracleOracle
- 如何開始學習 Node.js?Node.js
- eclipse學習從零開始Eclipse
- OpenResty的現狀、趨勢、使用及學習方法REST
- 從頭開始學習vue-routerVue
- 從零開始學習 Go ——安裝Go
- 學習React,從攻克JSX開始ReactJS
- 從這裡開始學習 LinuxLinux
- 30天從零開始學習SwiftSwift