Chinaunix首页 | 论坛 | 博客
  • 博客访问: 994702
  • 博文数量: 361
  • 博客积分: 25
  • 博客等级: 民兵
  • 技术积分: 1759
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-22 23:18
个人简介

学海无涯 个人blog lnmps.com 新站

文章分类

全部博文(361)

文章存档

2017年(1)

2015年(2)

2014年(55)

2013年(303)

分类: LINUX

2014-04-04 22:48:41

把Tengine改回NGINX

最近关于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-deve?l


yum install -y -y subversio?n (SVN,从GG CODE下载substitutions? 源码要用)


其次下载所需要的安装文件


下载Tengine


wget -c


下载Nginx-accesskey


wget -c http://wiki.nginx.org/images/5/51/Nginx-accesskey-2.0.3.tar.gz 

下载substitutions


svn checkout substitutions4nginx-read-onl?y






然后解压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./*
* Copyright (C) Igor Sysoev
*/




#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_




#define nginx_version      1000010
#define NGINX_VERSION      "1.0.10"? /* NGINX的版本号,最好别更改,更改了的话一会要改 substitutio?ns的源码,我这里是改了的,所以等下我去改substitutio?ns /*
#define NGINX_VER          "nginx/" NGINX_VERSION
/*
#define tengine_version    1002001
#define TENGINE_VERSION    "1.2.1"
#define TENGINE_VER        "Tengine/" TENGINE_VERSION
这里是tengine的版本号了。。我选择全部注释掉*/
#define NGINX_VAR          "NGINX"
#define NGX_OLDPID_EXT     ".oldbin"




#endif /* _NGINX_H_INCLUDED_ */?h
复制代码
保存后继续修改src/http/ngx_http_special_response.c 这个子程序在响应用户的http请求的时候,会反馈tengine的信息。。所以要


vi src/http/ngx_http_special_response.c


static u_char ngx_http_server_info_tail[] =
"" CRLF
"" CRLF
"" CRLF
;




static u_char ngx_http_error_full_tail[] =
"
Powered by " TENGINE_VER CRLF
" " CRLF
"" CRLF
;




static u_char ngx_http_error_tail[] =
"
Powered by Tengine" CRLF
"" CRLF
"" CRLF? 
复制代码
把里面的“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


static char ngx_http_server_string[] = "Server: Tengine" CRLF;
static char ngx_http_server_full_string[] = "Server: " TENGINE_VER CRLF;
复制代码
这个大家还是知道怎么改的吧。。。Server:随便你自己定义什么了。。。TENGINE_VER 还是改会NGINX_VER吧


改到这里之后。。。
TENGINE是改完了。。。其实。。直接用sed批量就可以改了。。。不过自从上次我用sed因为正则写错发生悲剧后(所有/etc/*.conf的文件都里面的空格都给我给去掉了。。。)所以这次我还是很低调的一个个改。。。而且要改的文件不多。


到这里了,如果您之前没有改nginx的版本号的话,那么你可以直接按照如下操作编译安装了。


./configure --prefix=/usr/local/cloud --user=cloud --group=cloud --with-poll_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_concat_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_sysguard_module --with-http_stub_status_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-backtrace_module --add-module=../../substitutions4nginx-read-only --add-module=../../nginx-accesskey-2.0.3  


make&&make install


运行完毕后nginx安装在/usr/local/cloud下


然后添加NGINX运行的用户和用户组


groupadd cloud


useradd -d /dev/null -s /sbin/nologin -g cloud cloud


然后chown -R cloud:cloud /usr/local/cloud


再直接启动nginx


/usr/local/cloud/nginx


这里不附送nginx 服务启动脚本。。






如果您在上面的nginx.h改了nginx版本的话,那么你还需要更改/root/soft/substitutions4nginx-read-only/ngx_http_subs_filter_module.?c这个文件,里面有判断nginx版本的代码


vi /root/soft/substitutions4nginx-read-only/ngx_http_subs_filter_module?.c


从1264行






#if defined(nginx_version) && nginx_version >= 8025 
    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;


#else
    pair->match_regex = ngx_regex_compile(&pair->match,
            options, cf->pool, &err);
#endif
复制代码
把if else endif注释掉


注释后如下


/* #if defined(nginx_version) && nginx_version >= 8025 */
    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;


/*#else
    pair->match_regex = ngx_regex_compile(&pair->match,
            options, cf->pool, &err);
#endif */
复制代码
保存后回到编译安装即可。

阅读(1092) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~