基于基于javascript处理处理nginx请求过程详解请求过程详解
主要介绍了基于javascript处理nginx请求过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具
有一定的参考学习价值,需要的朋友可以参考下
nginx是一个HTTP和反向代理服务器,目前很多网站都在使用nginx作为反向代理服务器。
njs是JavaScript语言的一个子集,它允许扩展nginx的功能,这点跟lua有点类似,不过采用的语言是javascript。
1. 安装安装nginx
要使用njs,需要安装一个nginx,这里的我使用的环境是Ubuntu18.04.4。
首先从http://nginx.org/en/download.html下载最新的stable version的nginx源码。
a. 解压源码
sudo tar zxvf nginx-1.18.0.tar.gz
b. 安装必要依赖库
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install openssl libssl-dev
# 如果是Centos系统,则使用下面的命令
# yum install pcre pcre-devel
# yum install zlib zlib-devel
# yum install openssl-devel
c. 拉取njs源码
# 安装mercurial
sudo apt-get install mercurial
# 拉取源码
cd /usr/local/src
hg clone http://hg.nginx.org/njs
d. 配置nginx
cd nginx-1.18.0
sudo ./configure \
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--add-module=/usr/local/src/njs/nginx
如果配置成功,可以看到如下信息:
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx"
nginx configuration file: "/usr/local/nginx/nginx.conf"
nginx pid file: "/usr/local/nginx/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
e. 编译源码
sudo make
# 如果没有安装make指令,可以通过下面的命令安装
评论0
最新资源