下载并安装

作为 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

然后,应使用配置参数从 nginx 根目录编译模块:--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 () 和 Library () paths 和 configuration 参数:-I-L--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 命令行实用程序,请运行 和 命令 从 NJS 根目录。 构建后,该实用程序以 ../configuremake njs./build/njs