我做的WordPress调整
- 数据库优化插件
PHP+APC速度php开opcache+mencached- MySQL的速度
- WordPress的插件删除
- nginx+ FastCGI
- 超高速缓存插件
- nginx代理缓存
- 排程开启wp-cron
赶潮流,现在都喜欢用Nginx做前端,然后后端放Apache,小内存我不喜欢这样的组合,非常吃内存
一、先调整数据库slow log
1 2 3 4 |
<pre class="wrap:true lang:default decode:true "> log-slow-queries = /var/log/mysql-slow.log long_query_time = 1 log-queries-not-using-indexes |
安装MYSQL优化插件,推荐两款:
WP-DBManager
http://wordpress.org/extend/plugins/wp-dbmanager/
Figment Thinking WordPress Database Table Optimizer
http://wordpress.org/extend/plugins/wordpress-database-table-optimizer/other_notes/
二、PHP+APC 速度更快php开opcache+mencached
APC代码缓存,可以让你的速度更快
https://caohuan.com/the-cache-wordpress-plugin-test.html
三、调整MYSQ的
关闭LOG:log=/var/log/mysql-query.log
我的my.cnf内容
1 2 3 4 5 6 7 8 9 10 11 12 |
<pre class="wrap:true lang:default decode:true "> skip-bdb thread_cache_size=64 query_cache_size=128M query_cache_limit=4MB table_cache=128 tmp_table_size=32M max_heap_table_size=32M key_buffer=256M sort_buffer=32M myisam_sort_buffer=32M wait_timeout=60 |
四、我目前保留开着的是w3 total cache其它的都是需时才开启
https://caohuan.com/new-plug-finishing.html
五、改Nginx+Apache为Nginx+FastCGI
参考:https://caohuan.com/wordpress-optimization.html
如果你使用spawn-fcgi
1 2 3 |
<pre class="wrap:true lang:default decode:true "> bind=/tmp/php.socket daemon $spawnfcgi -s ${bind} -u ${server_user} -g ${server_group} -P ${pidfile} -C ${server_childs} -f ${php_cgi} |
六、缓存插件,更多缓存插件可参考https://easyengine.io/tutorials/wordpress/wp-cron-crontab/
我在用的是w3 tatol cache,nginx+wordpress+w3设置参考:https://caohuan.com/the-cache-wordpress-plugin-test.html
七、nginx的代理缓存
Nginx+FastCGI
可参考下面的FastCGI设定
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 |
<pre class="wrap:true lang:default decode:true "> server { listen 8001; server_name _; access_log /var/log/nginx/fastcgi-access.log main; location / { root /var/www/html/htdocs; index index.php index.html index.htm; # static files if (-f $request_filename) { expires 30d; break; } # request to index.php if (!-e $request_filename) { rewrite ^(.+)$ /index.php?q=$1 last; } } location ~ \.php$ { root html; fastcgi_pass unix:/tmp/php.socket; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; include fastcgi_params; } } |
再看Proxy cache
1 2 3 |
<pre class="wrap:true lang:default decode:true "> proxy_cache_path /var/www/nginx_cache levels=1:2 keys_zone=czone:4m max_size=50m inactive=120m; proxy_temp_path /var/www/nginx_tmp; |
然后我链接起来
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 27 28 29 30 31 32 33 |
<pre class="wrap:true lang:default decode:true "> upstream backend { ip_hash; server 127.0.0.1:8001; } server { listen 80; server_name caohuan.com; access_log /var/log/nginx/caohuan.com.access.log; error_log /var/log/nginx/caohuan.com.error.log; location ~ .*\.(htm|html|jpg|JPG|gif|GIF|png|PNG|swf|SWF|css|CSS|js|JS|inc|INC|ico|ICO) { root /var/www/html; index index.html; ssi on; break; } location /wp-admin { proxy_pass http://backend; } location /wp-login.php { proxy_pass http://backend; } location / { if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) { set $do_not_cache 1; } if ($http_user_agent ~* “2.0\ 2MMP|240×320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800″) { set $do_not_cache 1; } proxy_no_cache $do_not_cache; proxy_cache_bypass $do_not_cache; proxy_pass http://backend; proxy_cache czone; proxy_cache_key $scheme$proxy_host$uri$is_args$args; proxy_cache_valid 200 10m; } } |
八、排程开启wp-cron
在wp-config.php插入
1 |
<pre class="wrap:true lang:default decode:true ">define('DISABLE_WP_CRON', true); |
关闭wordpress的定时任务。它是一个独立的功能,关闭了会影响常见的自动更新主题,自动更新插件,自动清理缓存,你可以安装一个插件来查看它排程了那些自动任务。
所以不能长期关闭它,可以通过crontab来定期执行它。
crontab -e编辑定时脚本,插入下列中的一条
1 |
<pre class="wrap:true lang:default decode:true ">*/10 * * * * curl https://caohuan.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1 |
比如我的是站群,我用的是下面这条
1 |
<pre class="wrap:true lang:default decode:true ">*/10 * * * * cd /var/www/caohuan.com; php /var/www/caohuan.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1 |
这两个的意思是每10分钟执行一次wp-cron.php,这个对我有什么好处,最明显的是你发布、更新文章(去掉了google公共资源问题、搜索推送的问题)不会在哪里卡卡的。