下载并安装

作为 Linux 软件包
安装 从源
构建 添加 QuickJS 引擎支持
构建 njs 命令行实用程序

作为 Linux 软件包安装

对于 Linux,可以使用 njs modules

  • nginx-module-njs— NJS 动态模块
  • nginx-module-njs-dbg— 调试符号nginx-module-njs

安装包后,njs 动态模块需要加载load_module命令:

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

然后,应使用--add-module配置参数:

./configure --add-module=path-to-njs/nginx

这些模块也可以构建为 dynamic

./configure --add-dynamic-module=path-to-njs/nginx

添加 QuickJS 引擎支持

确保您已构建 QuickJS 库:

git clone https://github.com/bellard/quickjs
cd quickjs
CFLAGS='-fPIC' make libquickjs.a

在模块编译步骤中,还会 指定 Include (-I) 和库 (-L) paths 的--with-cc-opt=--with-ld-opt=配置参数:

./configure --add-module=path-to-njs/nginx \
    --with-cc-opt="-I path-to-quickjs" \
    --with-ld-opt="-L path-to-quickjs"

构建 njs 命令行实用程序

要仅构建 njs 命令行实用程序,请运行./configuremake njs命令 从 NJS 根目录。 构建后,该实用程序以./build/njs.