從Nginx切換到Tengine的步驟分享
更新時間:2012年11月13日 11:46:52 作者:
由淘寶網(wǎng)發(fā)起的Web服務器 Tengine 可以被看作一個更好的Nginx,或者是Nginx的超集。它在Nginx的基礎(chǔ)上,針對大訪問量網(wǎng)站的需求,添加了很多高級功能和特性
從Nginx切換到Tengine主要是因為 concat 模塊(合并js、css),以及動態(tài)加載模塊功能(DSO)。
如果已經(jīng)用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的編譯參數(shù):
nginx -V
得到結(jié)果如下:
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. 根據(jù)上面第三行的配置編譯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
如果編譯中出現(xiàn)類似下面的錯誤,說明編譯依賴模塊不存在,你可以選擇安裝或者如果你不需要這個模塊的話,從上面的編譯腳本中刪除后再一次執(zhí)行編譯腳本,直到編譯完成:
這里提示XSLT模塊不存在,在上面的編譯腳本中搜索xslt,找到了--with-http_xslt_module,刪除就可以了,同樣注意前后的空格。
成功后提示如下(其中的路徑是跟編譯腳本有關(guān)的,所以可能會略有不同):
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. 繼續(xù)編譯(make就可以了,不需要make install):
make
7. 到objs目錄下編譯好的nginx文件:
8. 停止nginx:
9. 復制objs目錄下的nginx文件到/usr/sbin/nginx目錄,覆蓋前記得備份原來文件:
9. 測試nginx是否正常(/user/sbin目錄):
如果出現(xiàn)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 表示我們已經(jīng)成功從Nginx切換到了Tengine
如果已經(jīng)用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的編譯參數(shù):
復制代碼 代碼如下:
nginx -V
得到結(jié)果如下:
復制代碼 代碼如下:
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. 根據(jù)上面第三行的配置編譯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
如果編譯中出現(xiàn)類似下面的錯誤,說明編譯依賴模塊不存在,你可以選擇安裝或者如果你不需要這個模塊的話,從上面的編譯腳本中刪除后再一次執(zhí)行編譯腳本,直到編譯完成:
復制代碼 代碼如下:
./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,刪除就可以了,同樣注意前后的空格。
成功后提示如下(其中的路徑是跟編譯腳本有關(guān)的,所以可能會略有不同):
復制代碼 代碼如下:
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. 繼續(xù)編譯(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
如果出現(xiàn)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 表示我們已經(jīng)成功從Nginx切換到了Tengine
相關(guān)文章
nginx配置location總結(jié)location正則寫法及rewrite規(guī)則寫法
本文詳細講述了Nginx location正則寫法,Nginx 的Rewrite規(guī)則以及Nginx.conf中if指令與全局變量2018-10-10