主要更新:
- 全站HTTPS
- 全站CDN
- 服务器内存、硬盘升级。(512M RAM -> 1G RAM, 20G SSD ->25G SSD)
- 从SFO1机房迁移至SFO2
- Ubuntu14.04 -> Ubuntu18.04
迁站经验:
- UpdraftPlus Backups很好用。把wordpress站点上传到Google Drive,再从新的站点把备份下载下来,恢复即可。(同一个google drive app secret只能对应一个client。需要把原来的UpdraftPlus的secret从drive中删掉,新网站上的UpdraftPlus才能连接到drive上。
- 等网站内容准备就绪后,最后更改域名的解析IP地址,这样用户感觉不到迁站的,无缝连接。
- xmlrpc有安全漏洞,不能用。比如易受枚举攻击,DDos等。https://premium.wpmudev.org/blog/xml-rpc-wordpress/
优化经验:
用GTmetrix来测网站连接速度,并提供诊断报告。
Add Expires Headers
报告指出我的网站没有设置expires header,因此浏览器无法cache我的网站静态内容。网站的打开速度极慢。
解决方法:
首先确定你的apache2服务器安装的module是否包含headers和expires
1 |
apache2ctl -M |
如果没有的话,安装这两个module,并重启apache2
1 2 3 4 |
sudo a2enmod expires sudo a2enmod headers // restart apache2 systemctl restart apache2 |
你可以手动修改.htaccess文件,加入静态文件的cache规则。也可以下载wordpress插件,比如WP Fastest Cache
references:
https://superuser.com/questions/284898/how-to-check-which-apache-modules-are-enabled-installed
https://www.digitalocean.com/community/tutorials/how-to-configure-apache-content-caching-on-ubuntu-14-04
https://wordpress.org/support/topic/add-expires-headers-warning-non-3rd-party-sources/#post-11031564
全站HTTPS
用Certbot自动迁站,但要注意HTTP到HTTPS自动跳转的问题。
/etc/apache2/sites-enabled/XXX 、 .htaccess 、wp-config.php文件里都可能写有自动跳转的之指令。
免费的Certificate只有3个月有效期,到期前要人工renew。最好写一个cronjob来自动检测。
全站CDN
Cloud Flare有免费的CDN服务,直接修改domain server指向cloud flare的服务器就好。
References:
https://www.keycdn.com/support/check-if-cdn-is-working
SQL内存不足
迁站后,Mysql经常崩掉,查看/var/log/mysql/ log后发现如下错误
1 |
140124 17:35:15 InnoDB: Fatal error: cannot allocate memory for the buffer pool |
查询这个帖子后,改小SQL的buffer pool大小,以及改小Apache允许的并发连接数。
把Mysql的buffer pool size由默认的128M调成64M
1 2 |
# /etc/mysql/mysql.conf.d/mysqld.cnf innodb_buffer_pool_size = 64M |
把Apache的number of workers减少
1 2 3 4 5 6 7 8 |
# /etc/apache2/mods-enabled/mpm_prefork.conf <IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 5 MaxRequestWorkers 50 MaxConnectionsPerChild 0 </IfModule> |
有用的指令
1 2 3 4 5 6 7 8 9 10 11 12 |
# restart service systemctl restart <apache2/mysql> # check if a process is running ps -aux | grep 'process_name' # find string in a dir recursively grep -nr '<path>' -e '<string_pattern>' # send HTTP(S) request to a url and get the metadata only curl -I <static_file_on_your_website> # lookup DNS nslookup <hostname> # 压力测试 time ab -l -n 5000 -c 20 http://example.com/ |