WordPress访问速度优化 个人经验篇

95次阅读

共计 2563 个字符,预计需要花费 7 分钟才能阅读完成。

继上个帖子:https://hostloc.com/thread-1069801-1-1.html
原本从 Nginx 换成 OpenLiteSpeed 另外 +mysql+redis+php7.4 洛杉矶普通线路 VPS
感觉速度很理想了。深夜发帖让各位吴彦祖测速后, 大佬对 OpenLiteSpeed 做出了详细的了解。
经过今天再次与 NGINX 对比后, 发现无论是并发, 还是速度上 NGINX 确实略胜一筹,当然 也有可能我的测试方法不太对。
以下就分享下我的 0ip 小破站优化的方案,大佬勿喷, 有兴趣的吴彦祖可以拿测试站自行测试。
再贴个自己站的链接:www.i996.icu
NGINX 全局设置:
软件商店找到 Nginx,点击设置按钮,在配置修改中添加以下内容:
fastcgi_cache_path /tmp/wpcache levels=1:2 keys_zone=WORDPRESS:250m inactive=1d max_size=1G;
fastcgi_temp_path /tmp/wpcache/temp;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
# 忽略一切 nocache 申明,避免不缓存伪静态等
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
WordPress 访问速度优化 个人经验篇
网站设置
在宝塔后台的网站列表中,找到你的网站,并且点击设置按钮,将以下代码添加到配置文件中去:
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;
}
# 这里请参考你网站之前的配置,特别是 sock 的路径,弄错了就 502 了!如果你的网站使用 PHP7.4,就写 -74.sock
location ~ [^/].php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi-74.sock;
fastcgi_index index.php;
include fastcgi.conf;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
#新增的缓存规则
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
add_header X-Cache "$upstream_cache_status From $host";
fastcgi_cache WORDPRESS;
add_header Cache-Controlmax-age=0;
add_header Nginx-Cache "$upstream_cache_status";
add_header Last-Modified $date_gmt;
add_header X-Frame-Options SAMEORIGIN; # 只允许本站用 frame 来嵌套
add_header X-Content-Type-Options nosniff; # 禁止嗅探文件类型
add_header X-XSS-Protection "1; mode=block"; # XSS 保护
etagon;
fastcgi_cache_valid 200 301 302 1d;
}
# 缓存清理配置
location ~ /purge(/.*) {
allow 127.0.0.1;
allow " 服务器外网 IP"; # 引号要保留
deny all;
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
} 复制代码
加好之后的截图如下:
WordPress 访问速度优化 个人经验篇
NGINX 配置
伪静态:
location /
{
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent; 复制代码
添加好之后,重载 Nginx 设置,PHP 扩展安装 opcache 最后重启 php
WordPress 访问速度优化 个人经验篇

很值得借鉴啊不错不错自己绑定真的有用吗 如果并发大。万人访问的有效果吗

江南女子 发表于 2022-9-5 15:12
真的有用吗 如果并发大。万人访问的有效果吗

我拿 CC 测得我站没流量还可以具体的得自己试试了 OpenLiteSpeed 还是不如 Nginx,后者优化好了之后速度不比 ols 慢

louiejordan 发表于 2022-9-5 15:14
OpenLiteSpeed 还是不如 Nginx,后者优化好了之后速度不比 ols 慢

确实我现在就用的 nginx 多发点,我朋友需要

hdwan.net 发表于 2022-9-5 15:28
多发点,我朋友需要

你说的这个朋友莫非是?你那是没几篇文章而已。WordPress 访问速度优化 个人经验篇
19W 文章,你试试?WordPress 访问速度优化 个人经验篇

水牛 发表于 2022-9-5 15:38
你那是没几篇文章而已。
19W 文章,你试试?

水牛 发表于 2022-9-5 15:38
你那是没几篇文章而已。
19W 文章,你试试?

那大佬怎么搞定得分布式吗我自己 1ip 的小博客根本不在意优化 120W 文章你试试
WordPress 访问速度优化 个人经验篇WordPress 访问速度优化 个人经验篇技术派,很值得借鉴 OpenLiteSpeed+LSCache+Redis+MySQL+PHP7.4 不快你打我。

正文完
 0