OpenResty 安装

  1. 首先去OpenResty中文官网 http://openresty.org/cn/

2.然后添加 环境到Path

安装就这么多OK

运行一个Hello World

  1. 在任意一个地方新建一个文件夹(注意最好不要有中文路径)

例如在桌面 新建一个 example 文件夹, 目录结构如下 (目录树生成网站 http://dir.yardtea.cc/)

example
└─ hello
       ├─ conf
       │    └─ nginx.conf
       ├─ data
       │    └─ html
       │           └─ kbn.html
       └─ logs
            ├─ access.log
            ├─ error.log
            └─ nginx.pid
  1. 其中 logs 和conf 必要的, 里面的文件自己可以新建一个空文件

  2. 打开nginx.conf 如一配置

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 9000;
        default_type text/html;
        location / {
            root /data/html;
            index kbn.html;
        }
    }
}
  1. 启动 nginx
    • nginx -p 你的文件夹 -c conf/nginx.conf
    • 或 cd到你的 hello 使用 nginx -c conf/nginx.conf

    如果启动 报错 resty.core 找不到, 就把nginx安装目录中的 lua,luaLib 两个文件夹复制到你的project 里面去

  2. 当你修改你的配置之后 使用 nginx -s reload
  3. 停止 nginx nginx -s stop

conterOS 安装 OpenResty

官方说明:OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

下载地址:

  1. 安装依赖库:
$ yum install -y pcre-devel openssl-devel gcc curl
  1. 下载OpenResty版本:
$ wget https://openresty.org/download/openresty-1.15.8.1.tar.gz
  1. 解压:
$ tar -xzvf openresty-1.15.8.1.tar.gz
  1. 进入解压目录:
$ cd openresty-1.15.8.1/
  1. 检查配置环境, 生成 Makefile,默认安装到/usr/local/openresty:
$ ./configure
  1. 编译安装:
$ gmake && gmake install

安装结果:

mkdir -p /usr/local/openresty/site/lualib /usr/local/openresty/site/pod /usr/local/openresty/site/manifest
ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/bin/openresty

可以看到openresty 实际上是nginx的软连接。

  1. 查看版本号:
$ /usr/local/openresty/bin/openresty -v
nginx version: openresty/1.15.8.3
  1. 启动:
检验配置
/usr/local/openresty/bin/openresty -t
启动
/usr/local/openresty/bin/openresty
停止
/usr/local/openresty/bin/openresty -s stop
重新加载配置
/usr/local/openresty/bin/openresty -s reload
  1. 配置/lib/systemd/system/openresty.service,通过systemctl启动:
[Unit]
Description=openresty - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/openresty/bin/openresty -c /usr/local/openresty/nginx/conf/nginx.conf
ExecReload=/usr/local/openresty/bin/openresty -s reload
ExecStop=/usr/local/openresty/bin/openresty -s stop

[Install]
WantedBy=multi-user.target

添加openresty.service后,使配置文件生效:

$ systemctl daemon-reload

然后,就可以使用systemctl管理openresty:

启动
$ systemctl start openresty
停止
$ systemctl stop openresty
重载配置
$ systemctl reload openresty
重启
$ systemctl restart openresty

版权声明:本文为CSDN博主「depakin」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yisangwu/article/details/106728595

也可以参考这里 https://my.oschina.net/u/4305985/blog/3663887


Ubuntu OpenResty 安装的过程

先去官网 http://openresty.org/en/installation.html
先决条件 你应该有perl 5.6.1+,libpcre,libssl

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

然后要安装 zlib 参考 https://blog.csdn.net/weixin_43944305/article/details/108219746

wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar -xzvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install

再安装 openResty

wget https://openresty.org/download/openresty-1.19.9.1.tar.gz
tar -xvf openresty-1.19.9.1.tar.gz
cd openresty-1.19.9.1/
./configure -j2
make -j2
sudo make install

better also add the following line to your ~/.bashrc or ~/.bash_profile file.
export PATH=/usr/local/openresty/bin:$PATH

LuaRocks 安装

$ wget https://luarocks.org/releases/luarocks-3.7.0.tar.gz
$ tar zxpf luarocks-3.7.0.tar.gz
$ cd luarocks-3.7.0
$ ./configure && make && sudo make install
$ sudo luarocks install luasocket
$ lua
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
> require "socket"

如果是 5.1

$ ./configure --lua-version=5.1  --versioned-rocks-dir
$ make build
$ sudo make install
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容