WordPress优化秘籍

优化方案

服务器使用openresty,php,mysql,memcached,redis

插件:wpjam-basic,Nginx-helper

详细步骤

配置redis缓存

首先要安装好上述所有程序

然后修改网站的配置文件(vhost conf)

下面直接贴上我的配置文件,大家可以照修

  • upstream redis {
  • server 127.0.0.1:6379;
  • keepalive 512;
  • }
  • server
  • {
  • listen 80;
  • #listen [::]:80;
  • server_name locjj.com www.locjj.com;
  • rewrite ^(.*)$ https://www.$host$1 permanent;
  • }
  • server
  • {
  • listen 443 ssl http2;
  • #listen [::]:443 ssl http2;
  • server_name locjj.com www.locjj.com;
  • index index.html index.htm index.php default.html default.htm default.php;
  • root /home/wwwroot/locjj.com;
  • set $skip_cache 0;
  • #POST请求直接调用后端
  • if ($request_method = POST) {
  • set $skip_cache 1;
  • }
  • if ($query_string != “”) {
  • set $skip_cache 1;
  • }
  • #不要缓存以下部分
  • if ($request_uri ~* “/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml”) {
  • set $skip_cache 1;
  • }
  • #不缓存登陆用户和最近评论的用户
  • if ($http_cookie ~* “comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in”) {
  • set $skip_cache 1;
  • }
  • location /redis-fetch {
  • internal ;
  • set $redis_key $args;
  • redis_pass redis;
  • }
  • location /redis-store {
  • internal ;
  • set_unescape_uri $key $arg_key ;
  • redis2_query set $key $echo_request_body;
  • redis2_query expire $key 14400;
  • redis2_pass redis;
  • }
  • ssl_certificate /home/wwwroot/ssl/1.crt;
  • ssl_certificate_key /home/wwwroot/ssl/1.key;
  • ssl_session_timeout 5m;
  • ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  • ssl_prefer_server_ciphers on;
  • ssl_ciphers “TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5”;
  • ssl_session_cache builtin:1000 shared:SSL:10m;
  • # openssl dhparam -out /usr/local/openresty/nginx/conf/ssl/dhparam.pem 2048
  • ssl_dhparam /usr/local/openresty/nginx/conf/ssl/dhparam.pem;
  • include rewrite/wordpress.conf;
  • #error_page 404 /404.html;
  • # Deny access to PHP files in specific directory
  • #location ~ /(wp-content|uploads|wp-includes|images)/.*.php$ { deny all; }
  • # include enable-php.conf;
  • location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
  • {
  • expires 30d;
  • }
  • location ~ .*.(js|css)?$
  • {
  • expires 12h;
  • }
  • location ~ /.well-known {
  • allow all;
  • }
  • location ~ /.
  • {
  • deny all;
  • }
  • access_log off;
  • location ~ [^/].php(/|$) {
  • set $key “nginx-cache:$scheme$request_method$host$request_uri”;
  • try_files $uri =404;
  • srcache_fetch_skip $skip_cache;
  • srcache_store_skip $skip_cache;
  • srcache_response_cache_control off;
  • set_escape_uri $escaped_key $key;
  • srcache_fetch GET /redis-fetch $key;
  • srcache_store PUT /redis-store key=$escaped_key;
  • more_set_headers ‘X-Cache $srcache_fetch_status’;
  • more_set_headers ‘X-Store $srcache_store_status’;
  • #PHP版本号有出入的别弄错了
  • fastcgi_pass unix:/tmp/php-cgi.sock;
  • fastcgi_index index.php;
  • include fastcgi.conf;
  • fastcgi_param PHP_VALUE “open_basedir=$document_root:/tmp/:/proc/”;
  • }

修改好后重启openresty,去wordpress后台安装Nginx-Helper插件,开启redis缓存,其他全部默认即可

这个插件的作用是能够及时的刷新缓存

命中情况可以在服务器上执行

  • telnet 127.0.0.1 6379

WordPress优化秘籍

keyspace_hits为命中次数,keyspace_misses为未命中次数

这里可以看到命中率还是很高的

配置Memcached缓存

在wordpress后台安装wpjam-basic插件,然后点击扩展管理,微信扫码登录

然后将/wp-content/plugins/wpjam-basic/template/object-cache.php复制到/wp-content

即可开启Memcached缓存,点击WPJAM-系统信息可以查看详情

WordPress优化秘籍

WPJAM插件还有其他很多优化功能,大家可以自己摸索

小车博客下载必看

给TA打赏
共{{data.count}}人
人已打赏
WP教程

企业网站建设最重要的关键点是什么?

2021-1-15 13:51:53

WP教程

wordpress删除文章自动删除文章中的图片

2021-6-1 16:02:41




重要声明

本站资源来自会员发布以及互联网收集,不代表本站立场,如有侵犯你的权益请联系管理员-车车站内发信联系 我们会第一时间进行审核删除。站内资源为网友个人学习或测试研究使用,未经原版权作者许可,禁止用于任何商业途径!请用户仔细辨认内容的真实性,避免上当受骗!本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。请在下载24小时内删除!


如果遇到付费才可观看的文章,建议升级终身VIP。全站所有资源任意下免费看”。本站资源少部分采用7z压缩,为防止有人压缩软件不支持7z格式,7z解压,建议下载7-zip,zip、rar解压,建议下载WinRAR

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索