从Nginx切换到Tengine的步骤分享
程序员文章站
2023-11-16 11:34:10
从nginx切换到tengine主要是因为 concat 模块(合并js、css),以及动态加载模块功能(dso)。 如果已经用apt-get方式安装了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
上一篇: vue项目部署上线遇到的问题及解决方法