OpenResty安装、配置与使用

OpenResty最佳实践官网

安装前的准备

您必须将这些库 perl 5.6.1+libpcrelibssl安装在您的电脑之中。 对于 Linux来说, 您需要确认使用 ldconfig 命令,让其在您的系统环境路径中能找到它们。

apt-get install libpcre3-dev libssl-dev perl make build-essential curl zlib1g-dev

安装构建OpenResty

下载

从下载页 Download下载最新的 OpenResty® 源码包,并且像下面的示例一样将其解压:

tar -xzvf openresty-VERSION.tar.gz

VERSION 的地方替换成您下载的源码包的版本号,比如说 0.8.54.6

./configure

然后在进入 openresty-VERSION/ 目录, 然后输入以下命令配置:

默认, --prefix=/usr/local/openresty 程序会被安装到/usr/local/openresty目录。

您可以指定各种选项,比如

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

试着使用 ./configure --help 查看更多的选项。

配置文件(./configure script)运行出错可以到 build/nginx-VERSION/objs/autoconf.err 找到。 VERSION 的地方必须与OpenResty版本号相对应, 比如 0.8.54.6

make && make install

您可以使用下面的命令来编译:

如果您的电脑支持多核 make 工作的特性, 您可以这样编译:
make -j2

假设您是的机器是双核。

如果前面的步骤都没有问题的话,您可以使用下面的命令安装 OpenResty 到您的系统中:

make install

新手上路

新建OpenResty 工作目录

mkdir ~/work
cd ~/work
mkdir logs/ conf/

logs/ 为日志文件 conf/ 为配置文件

配置 nginx.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, world</p>")
            }
        }
    }
}

启动 Nginx 服务

假设 OpenResty 安装在目录 /opt/openresty,将给目录加入到环境路径

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

然后使用 nginx.conf配置文件启动nginx服务

nginx -p `pwd`/ -c conf/nginx.conf 

错误信息将会输出到 logs/error.log 文件中

访问 http://localhost:8080/ 将会输入

<p>hello, world</p>

停止 Nginx 服务

nginx -p ./ -s stop

至此,安装 测试openresty 完成

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值