找回密码
 立即注册
CeraNetworksBGVM服务器主机交流IP归属甄别会员请立即修改密码
查看: 99|回复: 7

阿里系装B份子们,哥把Tengine改回NGINX

[复制链接]

23

主题

420

回帖

1525

积分

金牌会员

积分
1525
发表于 2011-12-15 17:28:51 | 显示全部楼层 |阅读模式
d

首先,马云坑到了很多钱。。。所以确实有一批大神在为他干活

其次,现在阿里系出来又是出书又是演讲跳大神装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./*[ol]
  • * 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
  • [/ol]复制代码保存后继续修改src/http/ngx_http_special_response.c 这个子程序在响应用户的http请求的时候,会反馈tengine的信息。。所以要

    vi src/http/ngx_http_special_response.c[ol]
  • static u_char ngx_http_server_info_tail[] =
  • "[/td]" CRLF
  • "[/tr]" CRLF
  • "[/table]" 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
  • [/ol]复制代码把里面的“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[ol]
  • static char ngx_http_server_string[] = "Server: Tengine" CRLF;
  • static char ngx_http_server_full_string[] = "Server: " TENGINE_VER CRLF;
  • [/ol]复制代码这个大家还是知道怎么改的吧。。。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行[ol]
  • #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
  • [/ol]复制代码把if else endif注释掉

    注释后如下[ol]
  • /* #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 */
  • [/ol]复制代码保存后回到编译安装即可。。。。



    到此结束。。。
  • 回复

    使用道具 举报

    239

    主题

    632

    回帖

    3603

    积分

    论坛元老

    积分
    3603
    发表于 2011-12-15 17:42:24 | 显示全部楼层
    什么意思?
    回复

    使用道具 举报

    15

    主题

    52

    回帖

    181

    积分

    注册会员

    积分
    181
    发表于 2011-12-15 18:19:21 | 显示全部楼层
    不用
    回复

    使用道具 举报

    26

    主题

    198

    回帖

    602

    积分

    高级会员

    积分
    602
    发表于 2011-12-15 19:32:02 | 显示全部楼层
    不知所云,仍觉很屌
    回复

    使用道具 举报

    5

    主题

    38

    回帖

    101

    积分

    注册会员

    积分
    101
    发表于 2011-12-15 23:09:13 | 显示全部楼层
    楼主牛叉,膜拜
    回复

    使用道具 举报

    4

    主题

    107

    回帖

    304

    积分

    中级会员

    积分
    304
    发表于 2011-12-15 23:13:02 | 显示全部楼层
    技术贴
    回复

    使用道具 举报

    23

    主题

    420

    回帖

    1525

    积分

    金牌会员

    积分
    1525
     楼主| 发表于 2011-12-16 01:30:25 | 显示全部楼层
    自己顶自己
    回复

    使用道具 举报

    0

    主题

    13

    回帖

    32

    积分

    新手上路

    积分
    32
    发表于 2011-12-16 05:18:56 | 显示全部楼层
    不关我是 lnmp一键包小白鲁国


    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|HS2V主机综合交流论坛

    GMT+8, 2024-5-29 10:37 , Processed in 0.060721 second(s), 3 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表