今天制作了一个nginx的srpm包,分享给大家,主要是精简了nginx编译参数,去掉了不常用的mail、ipv6等模块,集成了第三方模块gperftools、GeoIP、nasxi、nginx_upstream_hash、ngx_cache_purge。默认的配置文件更适合lnmp或者负载均衡。 gperftools 是谷歌性能优化工具包,利用它的tcmalloc库,可提高nginx的内存使用效率; GeoIP是一个地理位置信息库; nasxi是为nginx量身定制的高性能web应用防火墙,有点类似于apache的mod_security,可以有效防止XSS跨站攻击和sql注入。 nginx_upstream_hash是nginx负载均衡算法,在后端是缓存系统(squid/varnish/memcached等)时,可以极大提高缓存命中率和缓存质量。 ngx_cache_purge 是nginx作为缓存服务器时,清除nginx自身缓存的模块。
安装编译方法(依赖epel仓库) - rpm -ivh nginx-1.2.8.excel.src.rpm
- cd ~/rpmbuild/SPEC
- rpmbuild -bp nginx.spec
- rpmbuild -ba nginx.spec
- rpm -ivh ~/rpmbuild/RPMS/x86_64/nginx-1.2.8-1.el6.excel.x86_64.rpm
gperftools 用法见配置文件,检查方法
naxsi 用法见配置文件
nginx_upstream_hash用法 - upstream backend {
- server 127.0.0.1:81
- server 127.0.0.1:82
- ...
- hash $request_uri;
- hash_method crc32;
- hash_again 10; # default 0
- }
注意:server语句不能写入weight等其他参数,原因见第一个参考文章
ngx_cache_purge使用方法 - http {
- proxy_cache_path /tmp/cache keys_zone=tmpcache:10m;
-
- server {
- location / {
- proxy_pass http://127.0.0.1:8000;
- proxy_cache tmpcache;
- proxy_cache_key $uri$is_args$args;
- }
-
- location ~ /purge(/.*) {
- allow 127.0.0.1;
- deny all;
- proxy_cache_purge tmpcache $1$is_args$args;
- }
- }
- }
后缀名限制,附件下载后直接去掉.zip后缀
|