vps中mc设置小记及nginx的w3tc设置相关

提醒:本文最后更新于 2840 天前,文中所描述的信息可能已发生改变,请仔细核实。

让memcache在linux启动是自动启动,请在ssh中vi /etc/rc.d/rc.local,加入:

/usr/local/bin/memcached -d -m 32 -u root -l 199.231.84.14 -p 11211 -c 256 -P /tmp/memcached.pid

让wordpress自动完成memcache设置,在wp-config.php中添加

global $memcached_servers;
$memcached_servers = array('default' => array(' 199.231.84.14: 11211'));

安装memcache前需要安装libevent(centos5),检测是否安装libevent成功的方法如下:

ls -al /usr/lib | grep libevent

通过netstat -ant可以来查看memcache是否启动,只要11211端口是活动就ok了

附上memcache小知识:

Nginx.conf的W3TC设置(for wp)(一般另放文件,然后include)

# BEGIN W3TC Page Cache cache
location ~ /wp-content/w3tc/pgcache.*html$ {
   add_header X-Powered-By "W3 Total Cache/0.9.2.4";
   add_header Vary "Accept-Encoding, Cookie";
}
location ~ /wp-content/w3tc/pgcache.*gzip$ {
   gzip off;
   types {}
   default_type text/html;
   add_header X-Powered-By "W3 Total Cache/0.9.2.4";
   add_header Vary "Accept-Encoding, Cookie";
   add_header Content-Encoding gzip;
}
# END W3TC Page Cache cache
# BEGIN W3TC Browser Cache
gzip on;
gzip_types text/css application/x-javascript text/x-component text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location ~ .(css|js|htc)$ {
   add_header X-Powered-By "W3 Total Cache/0.9.2.4";
}
location ~ .(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
   add_header X-Powered-By "W3 Total Cache/0.9.2.4";
}
location ~ .(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
   add_header X-Powered-By "W3 Total Cache/0.9.2.4";
}
# END W3TC Browser Cache
# BEGIN W3TC Minify core
rewrite ^/wp-content/w3tc/min/w3tc_rewrite_test$ /wp-content/w3tc/min/index.php?w3tc_rewrite_test=1 last;
rewrite ^/wp-content/w3tc/min/(.+.(css|js))$ /wp-content/w3tc/min/index.php?file=$1 last;
# END W3TC Minify core
# BEGIN W3TC Page Cache core
rewrite ^(.*/)?w3tc_rewrite_test$ $1?w3tc_rewrite_test=1 last;
set $w3tc_rewrite 1;
if ($request_method = POST) {
   set $w3tc_rewrite 0;
}
if ($query_string != "") {
   set $w3tc_rewrite 0;
}
if ($http_host != "kn007.net") {
   set $w3tc_rewrite 0;
}
set $w3tc_rewrite3 1;
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|index.php)") {
   set $w3tc_rewrite3 0;
}
if ($request_uri ~* "(wp-comments-popup.php|wp-links-opml.php|wp-locations.php)") {
   set $w3tc_rewrite3 1;
}
if ($w3tc_rewrite3 != 1) {
   set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(comment_author|wp-postpass|wordpress_[a-f0-9]+|wordpress_logged_in)") {
   set $w3tc_rewrite 0;
}
if ($http_user_agent ~* "(W3 Total Cache/0.9.2.4)") {
   set $w3tc_rewrite 0;
}
set $w3tc_ua "";
set $w3tc_ref "";
set $w3tc_ssl "";
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
   set $w3tc_enc _gzip;
}
set $w3tc_ext "";
if (-f "$document_root/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl.html$w3tc_enc") {
   set $w3tc_ext .html;
}
if (-f "$document_root/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl.xml$w3tc_enc") {
   set $w3tc_ext .xml;
}
if ($w3tc_ext = "") {
 set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
   rewrite .* "/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl$w3tc_ext$w3tc_enc" last;
}
# END W3TC Page Cache core

转载请注明转自:kn007的个人博客的《vps中mc设置小记及nginx的w3tc设置相关