OpenResty是一款基于Nginx和Lua的高性能Web平台,在nginx基础之上集成了大量的lua库,第三方模块等,以便搭建各种处理高并发、可扩展的Web应用、服务或网关,并且OpenResty完全兼容nginx所有的配置,可以直接当做nginx来使用,而且可以支持lua进行编程处理相应的逻辑,实现高并发的请求处理,可以弥补nginx不可编程的困难,所以是结合了nginx的异步模型加上Lua编程简单的两大优点,实现高性能可扩展的网关,下面就主要叙述下openresty的基本安装和配置

    openresty官网:http://openresty.org/

    下载页面:http://openresty.org/cn/download.html,官方提供针对不同平台的二进制包,我这使用的是源码包编译的方式安装,用二进制包安装更简单

    安装参考:http://openresty.org/cn/installation.html

    安装之前首先要确认系统的基础环境,我使用的是CentOS 7,确认环境如下:

yum install gcc

yum install

yum install

yum install

    5. 最后准备OpenResty源码包:openresty-1.17.8.2.tar.gz

    然后准备安装openresty,解压源码包:

tar -xvzf openresty-1.17.8.2.tar.gz
cd openresty-1.17.8.2

    然后设置配置选项:

./configure --prefix=/opt/openresty --with-luajit --with-http_iconv_module --with-http_postgres_module

./configure --help

make -j4
make install

nginx/sbin/nginx

    

openresty 功能介绍 openresty配置_openresty 功能介绍

    然后也可以单独自己随便找个目录创建自己的OpenResty项目,比如到自己的用户目录下操作:

mkdir ~/resty-work
cd ~/resty-work
# 创建conf和logs目录
mkdir conf logs

    然后在conf下创建配置文件:conf/nginx.conf,配置如下内容:

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 8080;
        location / {
            default_type text/html;
            content_by_lua_block {
                ngx.say("<p>hello, OpenResty!</p>")
            }
        }
    }
}

    这个配置和普通nginx一样,只是在其中嵌入了一行lua block用来输出内容,然后保存配置,为了之后执行方便可以将nginx二进制文件加入到PATH中:

export PATH=$PATH:/opt/openresty/nginx/sbin

nginx -p `pwd` -c conf/nginx.conf ,因为这次是单独启动项目,因此需要使用-p指定要运行的path,默认是openresty安装目录下的nginx目录,然后-c指定配置文件,默认是:conf/nginx.conf,这时pid文件就为~/resty-work/logs/nginx.pid,如果停止同样要指定目录和配置文件(如果不是默认): nginx -p `pwd` -c conf/nginx.conf -s stop

openresty 功能介绍 openresty配置_lua_02

    这样OpenResty就基本配置好了