lua-io-nginx-module-plus

注意:此库需要 OpenResty 1.21.4.3 或更高版本。

二进制安装程序的资源库

首先,我们需要使用下面的命令配置二进制安装程序的资源库。命令中的 “CLIENT_TOKEN” 需要替换为订阅邮件中的有效令牌。

curl -o get-xray-priv-lib-repo.sh https://pkg2.openresty.com/scripts/get-xray-priv-lib-repo.sh
sudo bash get-xray-priv-lib-repo.sh -l lua-io-nginx-module-plus -t CLIENT_TOKEN

安装

适用于 OpenResty-1.21.4.x

对于使用 yum 作为软件包管理器的 CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux 操作系统,执行以下命令安装私有库。

sudo yum makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus"
sudo yum install --disablerepo="*" --enablerepo="lua-io-nginx-module-plus" -y lua-io-nginx-module-plus-1.21.4

对于使用 dnf 作为软件包管理器的 Fedora 等操作系统,执行以下命令安装私有库。

sudo dnf makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus"
sudo dnf install --disablerepo="*" --enablerepo="lua-io-nginx-module-plus" -y lua-io-nginx-module-plus-1.21.4

对于使用 apt 作为软件包管理器的操作系统(如 Ubuntu/Debian),运行以下命令安装私有库。

sudo apt-get install -y lua-io-nginx-module-plus-1.21.4

适用于 OpenResty 1.25.3.x

对于使用 yum 作为软件包管理器的 CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux 操作系统,执行以下命令安装私有库。

sudo yum makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus"
sudo yum install --disablerepo="*" --enablerepo="lua-io-nginx-module-plus" -y lua-io-nginx-module-plus-1.25.3

对于使用 dnf 作为软件包管理器的操作系统(如 Fedora ),执行以下命令安装私有库。

sudo dnf makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus"
sudo dnf install --disablerepo="*" --enablerepo="lua-io-nginx-module-plus" -y lua-io-nginx-module-plus-1.25.3

对于使用 apt 作为软件包管理器的操作系统(如 Ubuntu/Debian),运行以下命令安装私有库。

sudo apt-get install -y lua-io-nginx-module-plus-1.25.3

升级

适用于 OpenResty-1.21.4.x

对于使用 yum 作为软件包管理器的 CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux 操作系统,执行以下命令安装私有库。

sudo yum makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus"
sudo yum update --disablerepo="*" --enablerepo="lua-io-nginx-module-plus" -y lua-io-nginx-module-plus-1.21.4

对于使用 dnf 作为软件包管理器的 Fedora 等操作系统,执行以下命令安装私有库。

sudo dnf makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus"
sudo dnf update --disablerepo="*" --enablerepo="lua-io-nginx-module-plus" -y lua-io-nginx-module-plus-1.21.4

对于使用 apt 作为软件包管理器的操作系统(如 Ubuntu/Debian),运行以下命令安装私有库。

sudo apt-get update
sudo apt-get install -y lua-io-nginx-module-plus-1.21.4

适用于 OpenResty 1.25.3.x

对于使用 yum 作为软件包管理器的 CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux 操作系统,执行以下命令安装私有库。

sudo yum makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus"
sudo yum update --disablerepo="*" --enablerepo="lua-io-nginx-module-plus" -y lua-io-nginx-module-plus-1.25.3

对于使用 dnf 作为软件包管理器的操作系统(如 Fedora ),执行以下命令安装私有库。

sudo dnf makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus,coro-nginx-module"
sudo dnf update --disablerepo="*" --enablerepo="lua-io-nginx-module-plus,coro-nginx-module" -y lua-io-nginx-module-plus-1.25.3

对于使用apt作为软件包管理器的操作系统,如Ubuntu/Debian,运行以下命令安装私有库。

sudo apt-get update
sudo apt-get install -y lua-io-nginx-module-plus-1.25.3

适用于 OpenResty 1.27.1.x

对于使用 yum 作为软件包管理器的 CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux 操作系统,执行以下命令安装私有库。

sudo yum makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus"
sudo yum update --disablerepo="*" --enablerepo="lua-io-nginx-module-plus" -y lua-io-nginx-module-plus-1.27.1

对于使用 dnf 作为软件包管理器的操作系统(如 Fedora ),执行以下命令安装私有库。

sudo dnf makecache --disablerepo="*" --enablerepo="lua-io-nginx-module-plus,coro-nginx-module"
sudo dnf update --disablerepo="*" --enablerepo="lua-io-nginx-module-plus,coro-nginx-module" -y lua-io-nginx-module-plus-1.27.1

对于使用 apt作为软件包管理器的操作系统(如Ubuntu/Debian`),运行以下命令安装私有库。

sudo apt-get update
sudo apt-get install -y lua-io-nginx-module-plus-1.27.1

升级 OpenResty

如果先前已安装了 openresty,请执行以下升级命令:

sudo yum upgrade -y openresty

使用方法

Nginx 配置

在使用 lua-io-nginx-module-plus 之前,需要在配置文件 nginx.conf 中添加以下配置项,以加载相关动态模块。

# load_module 指令必须位于 nginx.conf 顶部
load_module /usr/local/openresty/nginx/modules/ngx_http_lua_io_module.so;

thread_pool default threads=2 max_queue=10;
...

http {
    location /ngx_io {
        content_by_lua_block {
            local ngx_io = require "ngx.io"

            local file, err = ngx_io.open("/tmp/foo.txt", "w")
            if not file then
                ngx.log(ngx.ERR, "failed to open /tmp/foo.txt: ", err)
                return
            end

            local bytes, err = file:write("hello world\n")
            if err ~= nil then
                ngx.log(ngx.ERR, "failed to write: ", err)
                -- fall through
            end

            local ok, err = file:close()
            if err ~= nil then
                ngx.log(ngx.ERR, "failed to close: ", err)
                return
            end
        }
    }
}