由淘宝网发起的Web服务器 Tengine 可以被看作一个更好的Nginx,或者是Nginx的超集。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。
从Nginx切换到Tengine 1、
从Nginx切换到Tengine主要是因为 concat 模块(合并js、css),以及动态加载模块功能(DSO)。
如果已经用apt-get方式安装了Nginx,可以尝试以下步骤以切换到Tengine(不需要卸载Nginx):
1. 到官方下载你喜欢的Tengine版本,这里以最新版(1.4.0)为例,
1wget http://tengine.taobao.org/download/tengine-1.4.0.tar.gz
2. 解压缩:
1tar -xvzf tengine-1.4.0.tar.gz
3. 进入解压出来的文件夹:
1 cd tengine-1.4.0/
从Nginx切换到Tengine 2、
4. 查看当前Nginx的编译参数:
1nginx -V
得到结果如下:
1nginx: nginx version: nginx/1.0.5
2nginx: TLS SNI support enabled
3 nginx: configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.0.5/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.0.5/debian/modules/nginx-upstream-fair
从Nginx切换到Tengine 3、
5. 根据上面第三行的配置编译Tengine,具体做法:从--prefix=/etc/nginx开始复制第三行的代码,然后在--with-debug后面加上--with-http_concat_module(意前后需要有空格),并删掉从--add-module开始的代码(否则会编译不过),完整的编译脚本如下:
1./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_concat_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module
如果编译中出现类似下面的错误,说明编译依赖模块不存在,你可以选择安装或者如果你不需要这个模块的话,从上面的编译脚本中删除后再一次执行编译脚本,直到编译完成:
1./configure: error: the HTTP XSLT module requires the libxml2/libxslt
2 libraries. You can either do not enable the module or install the libraries.
从Nginx切换到Tengine 4、
这里提示XSLT模块不存在,在上面的编译脚本中搜索xslt,找到了--with-http_xslt_module,删除就可以了,同样注意前后的空格。
成功后提示如下(其中的路径是跟编译脚本有关的,所以可能会略有不同):
01Configuration summary
02 + using system PCRE library
03 + using system OpenSSL library
04 + md5: using OpenSSL library
05 + sha1: using OpenSSL library
06 + using system zlib library
07
08 nginx path prefix: "/etc/nginx"
09 nginx binary file: "/etc/nginx/sbin/nginx"
10 nginx configuration prefix: "/etc/nginx"
11 nginx configuration file: "/etc/nginx/nginx.conf"
12 nginx pid file: "/var/run/nginx.pid"
13 nginx error log file: "/var/log/nginx/error.log"
14 nginx http access log file: "/var/log/nginx/access.log"
15 nginx http client request body temporary files: "/var/lib/nginx/body"
16 nginx dso module path: "/etc/nginx/modules"
17 nginx http proxy temporary files: "/var/lib/nginx/proxy"
18 nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi"
19 nginx http uwsgi temporary files: "/var/lib/nginx/uwsgi"
20 nginx http scgi temporary files: "/var/lib/nginx/scgi"
从Nginx切换到Tengine 5、
6. 继续编译(make就可以了,不需要make install):
1make
7. 到objs目录下编译好的nginx文件:
1cd objs/
8. 停止nginx:
1service nginx stop
9. 复制objs目录下的nginx文件到/usr/sbin/nginx目录,覆盖前记得备份原来文件:
1cp /usr/sbin/nginx /usr/sbin/nginx.bak
2 cp nginx /usr/sbin/
从Nginx切换到Tengine 6、
9. 测试nginx是否正常(/user/sbin目录):
1nginx -t
如果出现syntax is ok,test is successful表示成功:
1the configuration file /etc/nginx/nginx.conf syntax is ok2configuration file /etc/nginx/nginx.conf test is successful
10. 重新启动nginx
1 service nginx start
访问服务器上一个不存在的页面,查看服务器是否是Tengine
01403 Forbidden02 03You don't have permission to access the URL on this server. Sorry for the inconvenience.04Please report this message and include the following information to us.05Thank you very much!06 07URL: http://10.20.131.181/doc08Server: ubuntu-bak09Date: 2012/10/06 17:54:5310Powered by Tengine/1.4.0
注意看最后一行:Powered by Tengine/1.4.0 表示我们已经成功从Nginx切换到了Tengine