0VPS调整,以提高网络性能

虽然我没有写很多新的文章最近,我花了大量时间更新和修订的事情幕后的侧, 即各种安全 (TLS) 在我的设置 VPS 承载几个网站,包括这一项。我还努力最近提高的另一件事,是提高我使用的gzip, 并呼吁brotli新格式

简要地, gzip的 (和brotli) can be used to com­press resources before they are sent to the browser, 这减少了发送的数据的量, and hence should mean a site loads faster. The down­side is that com­press­ing resources takes time, which could out­weigh the gains from the smal­ler sizes. The ideal solu­tion is to have resources com­pressed in advance, rather than com­pressed by the http serv­er in real­time. Most of my web­sites use word­press which con­tains lots of files in plu­gins, 主题等, so going through all of these and manu­ally com­press­ing them everytime there is an update would be imprac­tic­al. The answer is to use a script which mon­it­ors the sys­tem for file changes, and cre­ates com­pressed files as needed. Below is the script I have recently writ­ten to do exactly this.

#!/bin/bash                               

inotifywait -m -q -e CREATE -e MODIFY -e MOVED_TO -r "/无功/网络/" --格式 "%w ^%F" --excludei“。(JPG|PNG|GIF|ICO|日志|SQL|拉链|GZ|PDF|PHP|SWF|TTF|EOT|WOFF|CST|JST|BR|CTS)$“ |
while read file
do
if [[ $文件=〜 \.(CSS)$ ]];
then
fname="${文件%。*}"
如果 [ -f "$FNAME".min.css ]
then
rm -f $file.gz
rm -f $file.br
zopfli --gzip $file
bro --quality 11 --input $file --output $file.br
chmod 664 $file.br
chmod 664 $file.gz
chown wordpress:wordpress $file.br
chown wordpress:wordpress $file.gz
else
rm -f $file.gz
rm -f $file.br
cat $file | cleancss > $fname.cst
cat $file | cleancss | 兄弟 - 质量 11 --output $file.br
zopfli --gzip $fname.cst -c > $fname.css.gz
chmod 664 $file.br
chmod 664 $file.gz
chown wordpress:wordpress $file.br
chown wordpress:wordpress $file.gz
rm -f $fname.cst
fi
fi

if [[ $文件=〜 \.(JS)$ ]];
then
fname="${文件%。*}"
如果 [ -f "$FNAME".min.css ]
then
rm -f $file.gz
rm -f $file.br
zopfli --gzip $file
bro --quality 11 --input $file --output $file.br
chmod 664 $file.br
chmod 664 $file.gz
chown wordpress:wordpress $file.br
chown wordpress:wordpress $file.gz
else
rm -f $file.gz
rm -f $file.br
uglifyjs $fname.js > $fname.jst
zopfli --gzip $fname.jst -c > $fname.js.gz
bro --quality 11 --input $fname.jst --output $file.br
chmod 664 $file.br
chmod 664 $file.gz
chown wordpress:wordpress $file.br
chown wordpress:wordpress $file.gz
rm -f $fname.jst
fi
fi

origfs=$(WC -c < "$文件")
gzfs = $(WC -c <"$file.gz")
BRFS = $(WC -c <"$file.br")

如果 [ "$origfs" -LT "$gzfs" ];
then
rm $file.gz -f
fi
if [ "$origfs" -LT "$BRFS" ];
then
rm $file.br -f
fi

done

Leave a Reply