公司的项目使用http合并请求,本地环境一直没配,导致自动化发布的时候很不方便,抽点时间把nginx更换成tengine,记录下,过程很简单
上传和下载
Linux小白看过来,我们先学习下简单易用的上传/下载命令rz和sz,我们可以通过 yum install lrzsz 进行安装
上传(rz) --- receive 指服务器从本地接收
可以使用 rz -y 实现覆盖上传,上传窗口的默认目录可以在SSH客户端里进行设置
下载(sz) --- send 指服务器发送文件到本地
可以直接使用 sz filename,其中filename就是你想要下载的文件的名字,支持相对/绝对路径,如果是目录需要打包成单个文件在实现下载
Tengine安装
安装 Tengine 我们需要准备两个安装包
下载完成后,先对原先的 Nginx 服务进行备份
[root@4vm8r ~]# cd /usr/local/ [root@4vm8r local]# mv nginx nginx_bak
备份完成,开始源码安装
[root@4vm8r src]# tar xf google-perftools-1.8.2.tar.gz [root@4vm8r src]# cd google-perftools-1.8.2 [root@4vm8r google-perftools-1.8.2]# ./configure --enable-frame-pointers [root@4vm8r google-perftools-1.8.2]# make && make install //安装tengine [root@4vm8r src]# tar xf tengine-2.1.2.tar.gz [root@4vm8r src]# cd tengine-2.1.2 [root@4vm8r tengine-2.1.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-google_perftools_module --with-http_image_filter_module --with-http_realip_module --with-http_concat_module [root@4vm8r tengine-2.1.2]# make && make install
查看 nginx 版本
# nginx -V
如果遇到此错误:nginx: error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory
那就表示系统不知道xxx.so 放在那个目录下,这个时候就要在/etc/ld.so.conf中加入xxx.so所在的目录
一般而言,有很多so都会在/usr/local/lib这个目录下,所以在/etc/ld.so.conf中加入/usr/local/lib这一行,可以解决此问题
将 /etc/ld.so.conf 保存后,还要执行 /sbin/ldconfig –v 来更新下
然后再试下 #nginx -V
[root@localhost ~]# nginx -V Tengine version: Tengine/2.1.2 (nginx/1.6.2) built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) TLS SNI support enabled
至此表示已安装成功
用 ps -ef | grep nginx 可以看到nginx进程还在跑,用 pkill -9 nginx 将进程干掉,重启服务即可
其他配置
隐藏Tengine 版本信息 在前台的显示
http { #关闭 版本号信息设置 server_tag off; server_info off; server_tokens off; }
设置禁止通过 ip 访问,只能通过域名
server { #设置禁止通过 ip 访问,只能通过域名 listen 80 default; server_name _; return 500; }
因为在安装 Tengine 的时候加上了concat模块,可以使用http合并请求了,只需修改下server的配置
location ~ .*/.*css/ { concat on; #是否开启concat,默认是关闭的 concat_max_files 20; #允许concat的最大文件数,默认是10 } location ~ .*/.*js/ { concat on; concat_max_files 30; }