hhvm下WordPress的构建

似乎是Github page及类似服务的兴起,wordpress博客没有以前热门了,大家都流行弄静态博客了。
不过我还是比较习惯Wordpress,毕竟用了这么多年,很多组件都再熟悉不过,修改起来也非常迅速,效率还是第一位嘛。现在hhvm和nginx的配合使用,博客运行起来也是非常地快。

 

 

hhvm的安装

hhvm倒是非常容易地安装,只要根据 Github上面的指示来做就行了。需要注意的事情是,hhvm在CentOS6.5里面似乎兼容得不好,所以如果想继续使用CentOS,就要升级到CentOS7。这时候数据库就换成了Mariadb,所以原来熟悉的MySQL就不能用了(其实都一样)。

具体细节请见 网站架构更换

hhvm对于PDO的支持似乎并不是那么地好,幸亏Wordpress没有太多的PDO方面的应用。

 

 

 

Nginx针对Wordpress的缓存设置

事实上,如果使用hhvm的话,缓存与否显得并不是那么地重要了。每生成一个页面只需要消耗4MB的内存而且通常情况下在500ms以内。但是如果网站更新不频繁的话,配置一下还是挺好的。

server {
        listen                  ipv4地址:443;
        listen                  ipv6地址:443;
        server_name             note.masterchan.me;

        ssl     on;
        ssl_certificate         /etc/证书位置;
        ssl_certificate_key     /etc/密匙位置;
        #enables all versions of TLS, but not SSLv2 or 3 which are weak and now deprecated.
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

        #Disables all weak ciphers
        ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
        ssl_prefer_server_ciphers on;

        root                    /var/www/网页目录


        set $no_cache 0;
        #set $no_cache 1;

        # 不缓存POST操作
        if ($request_method = POST) {
                set $no_cache 1;
        }


        # 不缓存后台
        if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
                set $no_cache 1;
        }

        # 已登录的不缓存(防止留言串号)
        if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
                set $no_cache 1;
        }

        # 暂停缓存
             set $no_cache 1;


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


        charset utf-8;
        keepalive_timeout 30s;

        location ~* \.(ico|jpg|png|gif|css|js)$ {
                expires 30d;
                log_not_found off;
        }


        location ~ \.php$ {
                add_header              Cache-Control           no-cache;

                #fastcgi_pass    unix:/var/run/php-fpm/php-fcgi.sock;
                fastcgi_pass    unix:/var/lib/hhvm/hhvm.sock;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
                fastcgi_param   HTTPS                           on;
                include                 fastcgi_params;

                fastcgi_cache_bypass $no_cache;
                fastcgi_no_cache $no_cache;
                fastcgi_cache   fcgicache;
                fastcgi_cache_valid     200 3d;
                fastcgi_cache_min_uses  3;
                fastcgi_cache_key "$host$request_uri";
        }

        #for sitemap
        rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;
        rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;
        rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;
        rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;

}

 

关于fastcgi_cache 名称 的定义在nginx.conf文件里面

 fastcgi_cache_path /var/www/fastcgi_cache  levels=1:2  keys_zone=fcgicache:64m inactive=1d max_size=5g;

 

 

 

解决Wordpress偶尔的高TTFB问题

之前用wordpress的时候其实就有留意到,有时候ttfb竟然会突升至6秒以上,甚至达到了20秒。由于这个是偶然状态(平均刷10+次才出现一次),因此没有特别的注意。换上hhvm之后,wordpress的性能大幅提升,这个问题就显得非常明显了,感觉上不像是网页处理的问题,于是将MySQL的query全部都记录了下来。发现是一个叫 wp-cron 的东西,通过生产页面的时候随机触发这个部件并且校验时间,达到定时操作的目的(这个设计真的非常落后)。由于经常附带有一些联网检查更新的操作,所以执行时间非常长。因此关掉这个组件比较实际,我们可以通过在系统crond中设定达到真正地定时执行。

 

主要是在wordpress 地config文件 即wp-config.php 加入这样一行,即可禁用

/**
禁用wp-cron
 */
define('DISABLE_WP_CRON', true);

 

事实上,关闭这个之后wordpress的自动更新还是可以运作的,不知道为什么。

这篇博文发表在 开发运维 | Dev Ops 目录下,标签为 , ,
如需引用,请使用链接:https://note.mc256.dev/?p=656

This article published in 开发运维 | Dev Ops with tags , , .
Cite this page using this link:https://note.mc256.dev/?p=656

您的邮箱地址不会被公开,评论使用Gravatar头像。
Your email address will not be published. This blog is using Gravatar.

正在提交评论... Submitting ...
正在为您准备评论控件 Loading Comment Plugin
Copyright © 2013-2023 mc256. All Rights Reserved.
Powered by WordPress on top of a dual-stack k3s Cluster using JuiceFS.
Wordpress Theme Designed By mc256.
Encrypted By Let's Encrypt.  Hosted On Linode + OVH + AWS.
DNS Provided By Hostker.
Status Page by CloudFlare Worker.