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