lua-io-nginx-module-plus

Note: OpenResty 1.21.4.3 or higher is required for this library.

The repository of the binary installer

First, we need to configure the repository of the binary installer using the commands below. (The CLIENT_TOKEN in the commands needs to be replaced with a valid Token from the subscription email)

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

Installation

For OpenResty-1.21.4.x

For CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux operating systems using yum as the package manager, execute the following command to install the private libraries.

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

For operating systems such as Fedora that use dnf as package manager, execute the following command to install the private library.

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

For operating systems such as Ubuntu/Debian that use apt as the package manager, run the following command to install the private libraries.

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

For OpenResty 1.25.3.x

For CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux operating systems using yum as the package manager, execute the following command to install the private libraries.

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

For operating systems such as Fedora that use dnf as package manager, execute the following command to install the private library.

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

For operating systems such as Ubuntu/Debian that use apt as the package manager, run the following command to install the private libraries.

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

Upgrade

For OpenResty-1.21.4.x

For CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux operating systems using yum as the package manager, execute the following command to install the private libraries.

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

For operating systems such as Fedora that use dnf as package manager, execute the following command to install the private library.

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

For operating systems such as Ubuntu/Debian that use apt as the package manager, run the following command to install the private libraries.

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

For OpenResty 1.25.3.x

For CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux operating systems using yum as the package manager, execute the following command to install the private libraries.

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

For operating systems such as Fedora that use dnf as package manager, execute the following command to install the private library.

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

For operating systems such as Ubuntu/Debian that use apt as the package manager, run the following command to install the private libraries.

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

For OpenResty 1.27.1.x

For CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux operating systems using yum as the package manager, execute the following command to install the private libraries.

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

For operating systems such as Fedora that use dnf as package manager, execute the following command to install the private library.

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

For operating systems such as Ubuntu/Debian that use apt as the package manager, run the following command to install the private libraries.

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

Upgrade OpenResty

If openresty has been previously installed, please execute the following upgrade command:

sudo yum upgrade -y openresty

Usage

Nginx configuration

Before you can use lua-io-nginx-module-plus, you need to add the following configuration items to the configuration file nginx.conf to load the related dynamic modules.

# The load_module directive must be on top of 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

        }
    }
}