Rising Sun

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  148 随笔 :: 0 文章 :: 22 评论 :: 0 Trackbacks
http://vc.hsly0559.cn/c/20111216_957.html
首先,马云坑到了很多钱。。。所以确实有一批大神在为他干活

  其次,现在阿里系出来又是出书又是演讲跳大神装B。。不是牛人。。给我的感觉。。跳梁小丑一样,给后端的牛人抹黑,我实在看不习惯

  第三,最近关于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./*

  [code]

  * Copyright (C) Igor Sysoev

  */

  #ifndef _NGINX_H_INCLUDED_

  #define _NGINX_H_INCLUDED_

  #define nginx_version 1000010

  #define NGINX_VERSION "1.0.10" /* NGINX的版本号,最好别更改,更改了的话一会要改 substitutions的源码,我这里是改了的,所以等下我去改substitutions /*

  #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

  [/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/*.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行

  [code]

  #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 

  [/code]

  把if else endif注释掉

  注释后如下

  [code]

  /* #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 */

  [/code]

  保存后回到编译安装即可。。。。

  到此结束。。。

  

  





posted on 2013-05-16 16:54 brock 阅读(306) 评论(0)  编辑  收藏 所属分类: 学习总结

只有注册用户登录后才能发表评论。


网站导航: