Appearance
下载与安装
提示
来自deepseek解释
原文链接:https://nginx.org/en/docs/njs/install.html
以 Linux 软件包形式安装
对于 Linux 系统,可以使用 njs 模块软件包:
nginx-module-njs— njs 动态模块nginx-module-njs-dbg—nginx-module-njs软件包的调试符号
软件包安装完成后,需要使用 load_module 指令加载 njs 动态模块:
nginx
load_module modules/ngx_http_js_module.so;或
nginx
load_module modules/ngx_stream_js_module.so;从源码构建
可以使用以下命令克隆包含 njs 源码的仓库(需要 Git 客户端):
bash
git clone https://github.com/nginx/njs然后,应从 nginx 根目录使用 --add-module 配置参数编译模块:
bash
./configure --add-module=path-to-njs/nginx这些模块也可以构建为动态模块:
bash
./configure --add-dynamic-module=path-to-njs/nginx添加 QuickJS 引擎支持
确保已构建 QuickJS 库:
bash
git clone https://github.com/bellard/quickjs
cd quickjs
CFLAGS='-fPIC' make libquickjs.a在模块编译步骤中,还需通过 --with-cc-opt= 和 --with-ld-opt= 配置参数指定头文件包含(-I)和库文件路径(-L):
bash
./configure --add-module=path-to-njs/nginx \
--with-cc-opt="-I path-to-quickjs" \
--with-ld-opt="-L path-to-quickjs"构建 njs 命令行工具
如果只构建 njs 命令行工具,请在 njs 根目录下运行 ./configure 和 make njs 命令。构建完成后,该工具位于 ./build/njs。