一、nginx编译安装

1、下载源码包nginx-1.12.1,官网nginx.org
# wget http://nginx.org/download/nginx-1.12.1.tar.gz
2、解压源码包
#tar xf nginx-1.12.1.tar.gz
3、下载以下扩展module,保存到exp目录
  3.1 module 地址

module name

url

echo-nginx-modulehttps://github.com/openresty/echo-nginx-module.git
lua-nginx-modulehttps://github.com/openresty/lua-nginx-module.git
ngx_devel_kithttps://github.com/simpl/ngx_devel_kit.git
set-misc-nginx-modulehttps://github.com/openresty/set-misc-nginx-module.git
lua-upstream-nginx-modulehttps://github.com/openresty/lua-upstream-nginx-module.git

3.2 创建module存放目录

   # cd nginx-1.12.1 && mkdir exp && cd exp 

  3.3 下载moudle
  # git clone https://github.com/openresty/echo-nginx-module.git
  # git clone https://github.com/openresty/lua-nginx-module.git
  # git clone https://github.com/simpl/ngx_devel_kit.git
  # git clone https://github.com/openresty/set-misc-nginx-module.git
  # git clone https://github.com/openresty/lua-upstream-nginx-module.git

4、下载openssl、pcre(pcre 7.9以下版本不支持UTF8,如果用到UTF8,需要下载7.9以上的版本)
4.1 扩展链接

扩展名

url

opensslhttps://www.openssl.org/source/old/1.0.2/openssl-1.0.2j.tar.gz
pcrehttps://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.bz2
 


4.2 下载
#wget https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.bz2
#wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2j.tar.gz
4.3 解压到/usr/local
# tar xf  pcre-8.39.tar.bz2  -C /usr/local/
#tar xf openssl-1.0.2j.tar.gz -C /usr/local/


5、编译,注意红色标记信息,openssl、pcre指定的是源码目录,而不是编译安装完成后的目录

# export LUAJIT_LIB=/usr/local/luajit/lib&&export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1&&./configure --prefix=/usr/local/nginx-1.12.1 --with-http_sub_module  --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --add-module=exp/echo-nginx-module/ --add-module=exp/lua-nginx-module/ --add-module=exp/ngx_devel_kit/ --add-module=exp/set-misc-nginx-module/ --add-module=exp/lua-upstream-nginx-module --with-openssl=/usr/local/openssl-1.0.2j/ --with-http_v2_module --with-cc-opt='-O2' --with-pcre=/usr/local/pcre-8.39/ --with-http_flv_module --with-http_mp4_module --with-threads --with-file-aio --add-module=exp/nginx-ct/ --with-pcre-jit

6、此时不能离开进行make,如果立刻进行make,make install之后,会导致nginx不能支持UTF8重写,原因是pcre没有启用UTF8,所以要在此处修改pcre,启用UTF8;configure之后,会在当前目录生成一个新目录obj,obj目录下有一个Makefile文件,保存第三方模块信息,需要修改此文件,在pcre处添加--enable-utf8 --enable-unicode-properties 这两个选项

修改前:obj/Makefile

p_w_picpath2017-7-19%2010%3A50%3A25.png?versio 

修改后:obj/Makefile

p_w_picpath2017-7-19%2010%3A50%3A58.png?versio


7、编译
#make
8、安装
#make install

 

二、编译安装pcre

1、切换到pcre源代码目录
 #cd  /usr/local/pcre-8.39/

2、编译

#./configure  --enable-utf8 --enable-unicode-properties

3、编译

#make

4、安装

#make install

 

小结: 现在可以使用nginx,以及可以正常nginx调用pcre,实现各种正则过滤

参考链接(Nginx、PCRE和中文URL(UTF8编码)rewrite路径重写匹配问题):http://www.cnyou.org/post/205.html