把Tengine改回NGINX,又能用Tengine的一些特性

来源:互联网 发布:华为网盘网络连接失败 编辑:程序博客网 时间:2024/05/20 10:52
第三,最近关于Tengine的讨论很火,简单看了下,在大流量下确实表现不错,而且据说可以过滤掉一些攻击或类似攻击流量,这是其宣称的特性,也是我们要保留的。
最后,加上了substitutions和nginx-accesskey这两个模块,前一个可用在垃圾站建设、过滤网页非法信息上,后一个可以做防盗链,非常适合个人站长用。
下面来说改动和安装过程,以centos 6 x64为基础环境演示, 在/root/soft下载文件和修改文件、编译安装
mkdir /root/soft
cd /root/soft
首先安装依赖包:
 yum -y --noplugins install wget zip
 yum -y --noplugins install unzip
 yum -y --noplugins install gcc
 yum -y --noplugins install make
 yum -y --noplugins install pcre-devel
 yum -y --noplugins install openssl-devel
 yum -y --noplugins install gcc-c++
 yum -y --noplugins install curl-devel
 yum install -y -y subversion (SVN,从GG CODE下载substitutions 源码要用)
其次下载所需要的安装文件
下载Tengine
wget -c http://tengine.taobao.org/download/tengine-1.2.0.tar.gz
下载Nginx-accesskey
wget -c http://wiki.nginx.org/images/5/51/Nginx-accesskey-2.0.3.tar.gz
下载substitutions
svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only
 
然后解压tengine和nginx-access
tar zxvf tengine-1.2.0.tar.gz
tar zxvf Nginx-accesskey-2.0.3.tar.gz
解压后,进入tengine目录
cd tengine
root@localhost tengine]# pwd
/root/soft/cloud/tengine
[root@localhost tengine]# 
开始编辑nginx.h,nginx版本号和tengine的版本号都放在这个文件里
vi src/core/nginx.

#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_

#define nginx_version      1000010
#define NGINX_VERSION      "1.0.10"
#define NGINX_VAR          "NGINX"
#define NGX_OLDPID_EXT     ".oldbin"

#endif h
[/code]
保存后继续修改src/http/ngx_http_special_response.c 这个子程序在响应用户的http请求的时候,会反馈tengine的信息。。所以要
vi src/http/ngx_http_special_response.c
[code]
static u_char ngx_http_server_info_tail[] =
"</td>" CRLF
"</tr>" CRLF
"</table>" CRLF
;

static u_char ngx_http_error_full_tail[] =
"<hr/>Powered by " TENGINE_VER CRLF
"</body>" CRLF
"</html>" CRLF
;

static u_char ngx_http_error_tail[] =
"<hr/>Powered by Tengine" CRLF
"</body>" CRLF
"</html>" CRLF 
[/code]
把里面的“TENGINE_VER CRLF”改成"NGINX_VER CRLF" 和"Powered by Tengine" 改成"Powered by NGINX"或者其他任意你想改的
再来看
src/http/ngx_http_header_filter_module.c这个文件
vi src/http/ngx_http_header_filter_module.c
[code]
static char ngx_http_server_string[] = "Server: Tengine" CRLF;
static char ngx_http_server_full_string[] = "Server: " TENGINE_VER CRLF;
[/code]
这个大家还是知道怎么改的吧。。。Server:随便你自己定义什么了。。。TENGINE_VER 还是改会NGINX_VER吧
改到这里之后。。。
 TENGINE是改完了。。。其实。。直接用sed批量就可以改了。。。不过自从上次我用sed因为正则写错发生悲剧后(所有/etc
    ngx_regex_compile_t   rc;
    rc.pattern = pair->match;
    rc.pool = cf->pool;
    rc.err = err;
    rc.options = options;
    if (ngx_regex_compile(&rc) != NGX_OK) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
        return NGX_ERROR;
    }
    pair->match_regex = rc.regex;
[/code]
保存后回到编译安装即可。。。。
原创粉丝点击