介紹:
Nginx 采用一個 master 進程管理多個 worker 進程(master-worker)模式,基本的事件處理都在 woker 中,master 負責一些全局初始化,以及對 worker 的管理。在OpenResty中,每個 woker 使用一個 LuaVM,當請求被分配到 woker 時,將在這個 LuaVM 里創建一個 coroutine(協程)。協程之間數據隔離,每個協程具有獨立的全局變量_G。OpenResty致力於將服務器應用完全運行與nginx中,充分利用nginx事件模型進行非阻塞I/O通信。其對MySQL、redis、Memcached的I\O通信操作也是非阻塞的,可以輕松應對10K以上的超高連接並發。
1、安裝openresty
1)、通過在CentOS 系統中添加 openresty
倉庫,便於未來安裝或更新我們的軟件包(通過 yum update
命令)
sudo yum install yum-utils
sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
2)、安裝openresty
sudo yum install openresty
3)、安裝命令行工具 resty
sudo yum install openresty-resty
命令行工具 opm
在 openresty-opm
包里,而 restydoc
工具在 openresty-doc
包里頭。
4)、查看openresty
倉庫里頭的軟件包
sudo yum --disablerepo="*" --enablerepo="openresty" list available
至此安裝成功,默認安裝在 /usr/local/openresty
2、測試
1)、啟動
--此命令運行在/usr/local/openresty目錄下 sudo /sbin/service openresty start --停止 sudo /sbin/service openresty stop
3、hello word
1)、創建example文件夾
cd usr/ mkdir example
2)、創建lua.conf及lua腳本
cd example/ vim lua.conf
server { listen 80; server_name _; lua_code_cache off; #關閉lua緩存 location /lua { default_type 'text/html'; content_by_lua_file /usr/example/lua/test.lua; } }
--此文件夾用於存放lua腳本
mkdir luafile
vim test.lua
ngx.say("hello world");
3)、配置nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; include /usr/example/lua.conf;#引入lua腳本配置文件
server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
4)、重啟openrsty
openresty介紹參考自:https://www.cnblogs.com/zampo/p/4269147.html 以及自己的理解