centos7安装openresty

介绍:html

   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以上的超高链接并发。nginx

一、安装openrestyredis

   1)、经过在CentOS 系统中添加 openresty 仓库,便于将来安装或更新咱们的软件包(经过 yum update 命令)vim

sudo yum install yum-utils
sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

  2)、安装openrestycentos

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/openrestyapp

二、测试工具

  1)、启动

--此命令运行在/usr/local/openresty目录下
sudo /sbin/service openresty start 
--中止
sudo /sbin/service openresty stop

  

三、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介绍参考自:http://www.javashuo.com/article/p-gsorlxtu-w.html 以及本身的理解

相关文章
相关标签/搜索