很长一段时间没有写文章了,一是因为懒,二是实在太忙了。
正好最近整理服务器,现在把过程梳理一下,免得以后再重复造轮子。
1、使用腾讯Linux操作系统组TCPA内核
2、基本宝塔面板开启TLSV1.3和Brotli压缩
推荐阅读《WordPress启用Nginx缓存》
注:2019.03.13 腾讯Linux系统组已删除TCPA相关文章和下载
安装TCPA内核
腾讯内部使用的TCPA,现在OPEN出来。
基于RHEL7.4源码,定制化的TCPA。
站长、个人、企业均可以免费使用,对,完全免费,免费,免费!
官网:https://linux.qq.com/?p=238
下载地址:
1.定制的内核
链接:https://share.weiyun.com/588ZWL5 密码:m8dqmt2.TCPA安装包
链接:https://share.weiyun.com/5t1Da37 密码:ngcdpm
使用方法:
安装要求:
centos7以上,boot分区不小于500M(太小可能导致安装内核失败)。
把下载的内核与TCPA安装包上传到服务中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
1.安装必要依赖 # yum -y update # yum -y install net-tools 2.安装内核 # rpm –ivh kernel-3.10.0-693.5.2.tcpa06.tl2.x86_64.rpm --force //安装完成后一定要重启服务器 # reboot 3.安装TCPA # tar jxvf tcpa_packets_180619_1151.tar.bz2 # cd tcpa_packets //执行安装命令,会安装到 /usr/local/storage/tcpav2 下面。 # sh install.sh # cd /usr/local/storage/tcpav2 //启用TCPA(默认只加速80,443,8080这3个端口) # sh start.sh |
TCPA和BBR测试对比报告:https://linux.qq.com/?p=224
TCPA(默认只加速80,443,8080这3个端口),如需新增加速端口:
1 2 3 |
#vim /usr/local/storage/tcpav2/start.sh //第46行后添加 $BINDIR/$CTLAPP access add tip $ip tport 自定义端口 |
查看是否开启成功:
1 2 |
# lsmod|grep tcpa tcpa_engine 224249 0 |
卸载方法:
1 2 |
cd /usr/local/storage/tcpav2 sh uninstall.sh |
开启TLSV1.3和Brotli压缩
一般来说我们的VPS主机已经默认开启了GZIP压缩了,而Brotli与GZIP可以同时共存,当同时开启两种压缩算法时,Brotli 压缩等级优先级高于 Gzip。实际上,最新版的宝塔BT面板已经默认可以开启TLSV1.3。
修改网站配置文件了,在ssl_protocols 后面添加TLSv1.3,在ssl_ciphers添加数个加密套件,重启Nginx完成。
代码添加如下:
1 2 |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5; |
打开Chrome按F12可以看到www.234du.com已经成功使用了TLSv1.3
开启Brotli压缩
方法一:
利用宝塔自带的脚本:www/server/panel/install/nginx.sh对Nginx重新编译和升级
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#安装libbrotli cd /www/server git clone https://github.com/bagder/libbrotli cd libbrotli ./autogen.sh ./configure make && make install #下载ngx_brotli模块及其依赖: cd /www/server git clone https://github.com/google/ngx_brotli cd ngx_brotli && git submodule update --init #获取Nginx Arguments nginx -V #编辑配置 vi /www/server/panel/install/nginx.sh #在你需要安装的Nginx版本下增加:--add-module=/www/server/ngx_brotli if [ "${nginx_version}" == "1.12.2" ] || [ "${nginx_version}" == "1.14.2" ];then ./configure --user=www --group=www --prefix=${Setup_Path} --with-openssl=${Update_Path}/src/openssl --add-module=${Update_Path}/src/ngx_devel_kit --add-module=${Update_Path}/src/lua_nginx_module --add-module=${Update_Path}/src/ngx_cache_purge --add-module=${Update_Path}/src/nginx-sticky-module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_v2_module --with-http_gzip_static_module --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt="-Wl,-E" --with-pcre=pcre-${pcre_version} ${jemallocLD} --add-module=/www/server/ngx_brotli elif [ "${nginxVersion}" == "1.15.6" ]; then ./configure --user=www --group=www --prefix=${Setup_Path} --with-openssl=${Setup_Path}/src/openssl --add-module=${Setup_Path}/src/ngx_devel_kit --add-module=${Setup_Path}/src/lua_nginx_module --add-module=${Setup_Path}/src/ngx_cache_purge --add-module=${Setup_Path}/src/nginx-sticky-module --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt="-Wl,-E" --with-openssl-opt="enable-tls1_3 enable-weak-ssl-ciphers" ${jemallocLD} --add-module=/www/server/ngx_brotli elif [ "$nginx_version" == "openresty" ]; then ./configure --user=www --group=www --prefix=${Setup_Path} --with-openssl=${Update_Path}/src/openssl --with-pcre=pcre-${pcre_version} --add-module=${Update_Path}/src/ngx_cache_purge --add-module=${Update_Path}/src/nginx-sticky-module --with-luajit --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_v2_module --with-http_gzip_static_module --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt="-Wl,-E" ${jemallocLD} elif [ "${nginxVersion}" = "-Tengine2.2.3" ]; then ./configure --user=www --group=www --prefix=${Setup_Path} --with-openssl=${Update_Path}/src/openssl --add-module=${Update_Path}/src/ngx_devel_kit --add-module=${Update_Path}/src/lua_nginx_module --add-module=${Update_Path}/src/ngx_cache_purge --add-module=${Update_Path}/src/nginx-sticky-module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_v2_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt="-Wl,-E" --without-http_upstream_session_sticky_module --with-pcre=pcre-${pcre_version} --add-module=/www/server/ngx_brotli #最后,重新编译Nginx(请根据自己的需要来选择) sh /www/server/panel/install/nginx.sh install 1.15 |
方法二:
宝塔在默认编译nginx后,会保留源码,及必要的模块源码所以编译时无需再次下载。
默认安装脚本:/www/server/panel/install/nginx.sh ,nginx源码目录:/www/server/nginx/src/
使用Nginx -V查看已经编译的模块
把已经编译的模块复制到文本中,在最后面添加 --add-module=/www/server/ngx_brotli,然后再重新编译。
编译的时候会报错./configure: warning: the "--with-ipv6" option is deprecated, nginx 1.12.2已支持ipv6,不需要再单独指定–with-ipv6,所以编译的时候把 --with-ipv6去掉再编译就可以了。
建议:为防止连接中断,建议使用screen 打开SSH连接再执行编译命令。
完整的命令如下:
1 2 3 4 5 6 7 8 |
# cd /www/server/nginx/src/ # ./configure --user=www --group=www --prefix=/www/server/nginx --with-openssl=/www/server/nginx/src/openssl --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-openssl-opt='enable-tls1_3 enable-weak-ssl-ciphers' --with-ld-opt=-ljemalloc --add-module=/www/server/ngx_brotli # make # rm -f /www/server/nginx/sbin/nginx.old # mv /www/server/nginx/sbin/nginx /www/server/nginx/sbin/nginx.old # cp objs/nginx /www/server/nginx/sbin/nginx # make upgrade |
upgrade完毕后,使用 nginx -V 命令 再次查看版本信息。
在你的网站的配置文件中加入Brotli代码
1 2 3 |
brotli on; brotli_comp_level 6; brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml; |
关于Brotli一些参数的说明,你可以根据自己的需要来调整:
1 2 3 4 5 6 7 8 |
brotli on; #启用 brotli_comp_level 6; #压缩等级,默认 6,太高的压缩水平可能需要更多的 CPU brotli_buffers 16 8k; #请求缓冲区的数量和大小 brotli_min_length 20; #指定压缩数据的最小长度,只有大于或等于最小长度才会对其压缩。这里指定 20 字节 brotli_types *; #指定允许进行压缩类型 # brotli_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml text/html application/json image/svg application/font-woff application/vnd.ms-fontobject application/vnd.apple.mpegurl image/x-icon image/jpeg image/gif image/png image/bmp; brotli_static always; #是否允许查找预处理好的、以 .br 结尾的压缩文件,可选值为 on、off、always brotli_window 512k; #窗口值,默认值为 512k |
理论上讲Brotli压缩比比GZIP要高不少,所以对于网页打开速度也是有一定作用的,不过想要秒开的感觉,还是先从硬件上提升一下速度吧。
文章参考及摘录:
https://wzfou.com/tlsv1-3-brotli/
https://www.lijian.me/141.html
文章评论
WordPress的优化问题,我觉得你这算是另辟蹊径了。很多人用WordPress做博客,纠结于速度,就各种插件各种缓存,这样你还不如去用类似织梦的CMS做博客。
WordPress若是想速度快,关键还是线路和空间。其他的于WordPress无关!
@飞酷网 我有点喜欢折腾,wordpress插件多了会影响。而且wp定位是博客程序,但是很多人硬要做成CMS,速度慢无非是引用了google字体、文章图片过大、头像服务器在国外,其它的感觉没什么好优化的。
一如既往的表示支持!