Nginx常用模块

2017-01-26  本文已影响439人  神农民

本文介绍了几个Nginx常用模块的使用方法。

ngx_http_ssi_module

官方说明文档:

http://nginx.org/en/docs/http/ngx_http_ssi_module.html

要点:

扩展:

在官方文档中有很多配置和命令,根据自己需要选用即可。

http_ssl_module

配置选项:加入 ssl 模块

./configure \
    --with-http_ssl_module

make 
cp -f objs/nginx /usr/local/nginx/sbin/nginx

生成证书

可以通过以下步骤生成一个简单的证书:

首先,进入你想创建证书和私钥的目录,例如:

$ cd /usr/local/nginx/conf

创建服务器私钥,命令会让你输入一个口令:

$ openssl genrsa -des3 -out server.key 1024

创建签名请求的证书(CSR):

$ openssl req -new -key server.key -out server.csr

在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:

$ cp server.key server.key.org
$ openssl rsa -in server.key.org -out server.key

配置nginx

最后标记证书使用上述私钥和CSR:

$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

修改Nginx配置文件,让其包含新标记的证书和私钥:

server {
    server_name localhost;
    listen 443 ssl;
    
    ssl_certificate     /usr/local/nginx/conf/server.crt;
    ssl_certificate_key /usr/local/nginx/conf/server.key;
    
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;
    keepalive_timeout   70;
}

重启nginx。

http_image_filter_module

安装 ImageFilter 模块依赖的库

apt-get install libgd2-xpm-dev

编译与安装

./configure \
    --with-http_image_filter_module
make
cp -f objs/nginx /usr/local/nginx/sbin/nginx

配置

location ^~ /images/ {
    root html;
    image_filter   resize  100 100;
}

访问 /images/bg001.jpg

即可得到压缩后的照片。

第三方模块:Foot Filter

寻找模块

这里有很多第三方模块:

https://www.nginx.com/resources/wiki/modules/index.html

我们从中挑选一个看似功能简单的来使用一下:Foot Filter

https://github.com/shennongmin/nginx-http-footer-filter

Footer Filter 下载、编译、安装以及使用

参考:https://github.com/shennongmin/nginx-http-footer-filter/blob/master/README.md

编译前Nginx配置选项

./configure \
    --with-http_image_filter_module \
    --with-http_ssl_module \
    --add-module=/root/nginx-http-footer-filter
    
make
cp -f objs/nginx /usr/local/nginx/sbin/nginx

配置 Footer Filter

location / {
    ## Using the $date_gmt variable from the SSI module (prints a
    ## UNIX timestamp).
    footer "<!-- $date_gmt -->";
    index index.html;
}

引入 Tengine

官方:

http://tengine.taobao.org/

简介

Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能
和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。它的最终目标是打
造一个高效、稳定、安全、易用的Web平台。

从2011年12月开始,Tengine成为一个开源项目,Tengine团队在积极地开发和维护着它。Tengine团队的核心成员
来自于淘宝、搜狗等互联网企业。Tengine是社区合作的成果,我们欢迎大家参与其中,贡献自己的力量。

特性


阅读原文 | 作者官网 | 公众号 | Feed | 订阅 | 发私信

上一篇 下一篇

猜你喜欢

热点阅读