set-misc-Nginx-module模块是标准的HttpRewriteModule指令的扩展,提供更多的功能,如URI转义与非转义、JSON引述、Hexadecimal/MD5/SHA1/Base32/Base64编码与解码、随机数等等。在后面的应用中,都将会接触使用到这个模块的。该模块是由章亦春先生开发的,他开发的其他模块应用也会使用到这个模块的。充分使用Nginx非阻塞模式,对性能上有极大的提高,我个人认为很有必要去弄懂弄透Nginx,通过自己去动手动脑用实例来加以验证,不断的对模块参数命令加以理解,在实际环境中应用自如。
这两个模块的主页分别是
标准模块ngx_http_rewrite_module
http://Nginx.org/en/docs/http/ngx_http_rewrite_module.html
第三方模块set-misc-Nginx-module
ngx_set_misc - VarIoUs set_xxx directives added to Nginx's rewrite module (md5/sha1,sql/json quoting,and many more)
https://github.com/openresty/set-misc-Nginx-module
下载源码
cd /usr/local/src
wget https://github.com/openresty/set-misc-Nginx-module/archive/v0.31.tar.gz
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar zxvf v0.31.tar.gz
tar zxvf v0.3.0.tar.gz
编译安装
cd Nginx-1.12.2
./configure --with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.41 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.1.0g \
--with-http_stub_status_module \
--add-module=/usr/local/src/ngx_cache_purge \
--add-module=/usr/local/src/ngx_req_status \
--add-module=/usr/local/src/echo-Nginx-module \
--add-module=/usr/local/src/ngx_devel_kit-0.3.0 \
--add-module=/usr/local/src/set-misc-Nginx-module-0.31
make
make install
注意这里set-misc-Nginx-module依赖ngx_devel_kit模块,且--add-module=ngx_devel_kit一定要早于--add-module=set-misc-Nginx-module
配置
curl 'http://localhost:8082/test?a=3&b=4'
curl 'http://localhost:8082/test/hello%20world?a=3&b=4'
curl 'http://localhost:8082/test?name=Tom&class=3'
curl 'http://localhost:8082/test?name=hello%20world&class=9'
curl 'http://localhost:8082/test?NAME=Marry'
更复杂的指令待后续继续补充
参考文献
[1].https://github.com/openresty/set-misc-Nginx-module
[2].http://www.ttlsa.com/Nginx/Nginx_set-misc-Nginx-module-module-description/
[3].https://github.com/openresty/set-misc-Nginx-module#installation
这两个模块的主页分别是
标准模块ngx_http_rewrite_module
http://Nginx.org/en/docs/http/ngx_http_rewrite_module.html
第三方模块set-misc-Nginx-module
ngx_set_misc - VarIoUs set_xxx directives added to Nginx's rewrite module (md5/sha1,sql/json quoting,and many more)
https://github.com/openresty/set-misc-Nginx-module
下载源码
cd /usr/local/src
wget https://github.com/openresty/set-misc-Nginx-module/archive/v0.31.tar.gz
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar zxvf v0.31.tar.gz
tar zxvf v0.3.0.tar.gz
编译安装
cd Nginx-1.12.2
./configure --with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.41 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.1.0g \
--with-http_stub_status_module \
--add-module=/usr/local/src/ngx_cache_purge \
--add-module=/usr/local/src/ngx_req_status \
--add-module=/usr/local/src/echo-Nginx-module \
--add-module=/usr/local/src/ngx_devel_kit-0.3.0 \
--add-module=/usr/local/src/set-misc-Nginx-module-0.31
make
make install
注意这里set-misc-Nginx-module依赖ngx_devel_kit模块,且--add-module=ngx_devel_kit一定要早于--add-module=set-misc-Nginx-module
配置
location /test { echo "uri = $uri"; echo "request_uri = $request_uri"; echo "name: $arg_name"; echo "class: $arg_class"; set_unescape_uri $name $arg_name; set_unescape_uri $class $arg_class; echo "name: $name"; echo "class: $class"; }
更完整的Nginx.conf配置参见
https://github.com/taoyunxing/github_test/blob/master/Nginx.conf
测试
curl -v 'http://localhost:8082/test'curl 'http://localhost:8082/test?a=3&b=4'
curl 'http://localhost:8082/test/hello%20world?a=3&b=4'
curl 'http://localhost:8082/test?name=Tom&class=3'
curl 'http://localhost:8082/test?name=hello%20world&class=9'
curl 'http://localhost:8082/test?NAME=Marry'
curl 'http://localhost:8082/test?Name=Jimmy'
更复杂的指令待后续继续补充
参考文献
[1].https://github.com/openresty/set-misc-Nginx-module
[2].http://www.ttlsa.com/Nginx/Nginx_set-misc-Nginx-module-module-description/
[3].https://github.com/openresty/set-misc-Nginx-module#installation