下载和安装
作为 Linux 包安装 从源代码构建 添加 QuickJS 引擎支持 构建 njs 命令行工具 |
作为 Linux 包安装
对于 Linux,可以使用 njs 模块的软件包
-
nginx-module-njs
— njs 动态模块 -
nginx-module-njs-dbg
—nginx-module-njs
软件包的调试符号
软件包安装后,需要使用 load_module
指令加载 njs 动态模块
load_module modules/ngx_http_js_module.so;
或
load_module modules/ngx_stream_js_module.so;
从源代码构建
njs 源代码的仓库可以使用以下命令克隆(需要 Git 客户端)
git clone https://github.com/nginx/njs
然后应从 nginx 根目录使用 --add-module
配置参数编译模块
./configure --add-module=path-to-njs
/nginx
模块也可以构建为动态模块
./configure --add-dynamic-module=path-to-njs
/nginx
添加 QuickJS 引擎支持
确保您已构建 QuickJS 库
git clone https://github.com/bellard/quickjs cd quickjs CFLAGS='-fPIC' make libquickjs.a
在模块编译步骤中,还需要使用 --with-cc-opt=
和 --with-ld-opt=
配置参数指定包含路径 (-I
) 和库路径 (-L
)
./configure --add-module=path-to-njs
/nginx \ --with-cc-opt="-Ipath-to-quickjs
" \ --with-ld-opt="-Lpath-to-quickjs
"
构建 njs 命令行工具
要仅构建 njs 命令行工具,请从 njs 根目录运行 ./configure
和 make njs
命令。构建完成后,该工具位于 ./build/njs
。