分类目录归档:linode

disable wp-cron.php

trace wp-super-cache的时候,发现后台有很多wp-cron.php的调用,每一次访问页面都会调用。

01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 In WP Cache Phase 2
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Setting up WordPress actions
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Not caching POST request.
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Cache garbage collection.
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Cleaning expired cache files in /****/public_html/wp-content/cache/
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 Doing GC on supercache dir: /****/public_html/wp-content/cache/supercache
01:32:22 /wp-cron.php?doing_wp_cron=1341019942.6320919990539550781250 gc: could not delete /****/public_html/wp-content/cache/supercache/6658.net/2012/01 as it’s not empty: 30

google之,发现该进程会占用很多系统资源。用google到的如下方法disable
在wp-config.php中添加

define(‘DISABLE_WP_CRON’, true);

然后在系统的crontab中添加

0,30 * * * * php -q /path_to_your_website/public_html/wp-cron.php

参考文档
http://blog.mellowhost.com/reducing-cpu-usage-for-wordpress-users.html

nginx+wp-super-cache不生成静态cache文件

网站迁移到nginx后,所有原来apache下面的配置文件都要重新写。
配置完wp-super-cache后,查看后台,发现cache目录已经建立,但是没有生成html文件。
打开wp-super-cache的debug功能,查看后台log

00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Cookie detected: wordpress_logged_in_08459be021d7ddc91806841039286bce
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ No wp-cache file exists. Must generate a new one.
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Cookie detected: wordpress_logged_in_08459be021d7ddc91806841039286bce
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ In WP Cache Phase 2
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Setting up WordPress actions
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Supercache caching disabled. Only using wp-cache. Non empty GET request.
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Created output buffer
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Output buffer callback
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Supercache disabled: GET or feed detected or disabled by config.
00:23:15 /2012/06/27/yourls-rewrite-apache-to-nginx/ Writing non-gzipped buffer to wp-cache cache file.

发现是因为有GET参数传递给了wp-super-cache,所以disabled.
wordpress所有响应都是rewrite给index.php的,检查nginx rewrite规则。发现确实使用用参数传递给index.php的,

try_files $uri/ $uri /index.php?q=$uri&$args;

网上查找一下,换成如下的rewrite方法

if (!-e $request_filename) { rewrite ^/(.+)$ /index.php last; }

reload配置之后,再次访问同一页面,后台trace如下

01:11:49 /2012/06/27/yourls-rewrite-apache-to-nginx/ Sending buffer to browser
01:11:49 /2012/06/27/yourls-rewrite-apache-to-nginx/ wp_cache_shutdown_callback: collecting meta data.
01:11:49 /2012/06/27/yourls-rewrite-apache-to-nginx/ Did not write meta file: wp-cache-6848e4f0747fac2d2b5b769950bff440.meta *1* *0* *1*
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ supercache dir: /****/public_html/wp-content/cache/supercache/3qs.com/2012/06/27/yourls-rewrite-apache-to-nginx/
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ No wp-cache file exists. Must generate a new one.
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ In WP Cache Phase 2
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Setting up WordPress actions
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Created output buffer
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Output buffer callback
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Anonymous user detected. Only creating Supercache file.
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Writing non-gzipped buffer to supercache file.
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Renamed temp supercache file to /****/public_html/wp-content/cache/supercache/3qs.com/2012/06/27/yourls-rewrite-apache-to-nginx/index.html
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ Sending buffer to browser
01:13:08 /2012/06/27/yourls-rewrite-apache-to-nginx/ wp_cache_shutdown_callback: collecting meta data.

到后台服务器上产看, 已经生成了对应的index.html静态文件了,访问速度也从1500多ms降到500多ms,多次访问,会返回304,在本地也cache了。。

[09:17:41.414] GET http://3qs.com/2012/06/27/yourls-rewrite-apache-to-nginx/ [HTTP/1.1 304 Not Modified 204ms]

-THE END-

yourls rewrite apache to nginx

Apache rewrite .htaccess file

# BEGIN YOURLS

RewriteEngine on

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+/?$ /yourls-infos.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+all/?$ /yourls-infos.php?id=$1&all=1 [L]

# END YOURLS

explain

# BEGIN YOURLS

RewriteEngine on
##This line starts the mod_rewrite module

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
##如果访问的文件存在,就不进行rewrite.
RewriteCond %{REQUEST_FILENAME} !-d
##如果访问的目录存在,就不进行rewrite.

RewriteRule ^([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+/?$ /yourls-infos.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)\+all/?$ /yourls-infos.php?id=$1&all=1 [L]

# END YOURLS

#####Nginx

location /{
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = “21”){
rewrite ^/([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 last;
rewrite ^/([0-9A-Za-z]+)\+/?$ /infos.php?id=$1 last;
rewrite ^/([0-9A-Za-z]+)\+all/?$ /infos.php?id=$1&all=1 last;
}
}