I heard that js can be used in nginx. nginx has use quickjs ,so we can use js in nginx config. That is exciting to me, I want to try it.
But when I see the doc, I am crying. It is so complicated. I have to download source for njs and quickjs, and nginx. After all three source download, I have to run configure \ make && make install . Oh my god
I try to download all the source files
git clone https://github.com/nginx/njs
wget http://nginx.org/download/nginx-1.25.3.tar.gz # 确保版本 ≥ 1.23.0
# 下载 OpenSSL 源码(以 3.0.8 为例)
wget https://www.openssl.org/source/openssl-3.0.8.tar.gz
tar -zxvf openssl-3.0.8.tar.gz
cd openssl-3.0.8
git clone https://github.com/bellard/quickjs
cd quickjs/
CFLAGS='-fPIC' make libquickjs.a # 生成位置无关代码
project_root/
├── nginx-1.25.3/ # Nginx 源码目录
└── quickjs/ # QuickJS 源码目录(需手动创建或克隆)
└── njs/ # QuickJS 源码目录(需手动创建或克隆)
# 授予当前用户读取权限
sudo chmod -R 755 ../quickjs
- I feel so disappointed. We need to configure the file with command below
./configure --add-dynamic-module=../njs/nginx --with-openssl=../openssl-3.0.8 --with-cc-opt="-I $(pwd)/../quickjs" --with-ld-opt="-L $(pwd)/../quickjs"
After configure step, we still need to make and make install
make && sudo make install
I run nginx start .something wrong again, It shows mismatch for njs and nginx. I try to run command
whereis nginx
nginx: /opt/homebrew/bin/nginx /opt/homebrew/share/man/man8/nginx.8
It seems that I dont use the nginx I compiled. I tried to use direct path for nginx and then It can not find correct config file. So I decide to use all direct path
./objs/nginx -c ~/workspace/nginx-1.25.3/conf/nginx.conf
even if the config file use direct path
Stop the nginx
./objs/nginx -c ~/workspace/nginx-1.25.3/conf/nginx.conf -s stop
start
./objs/nginx -c ~/workspace/nginx-1.25.3/conf/nginx.conf
visit the http://localhost
{
"message": "Request processed at 1758537787024",
"stats": {
"headerCount": 15,
"customHeaders": 0
},
"serverInfo": "GET / HTTP/1.1"
}
Top comments (0)