目录
- 处理站点健康问题
- 常用插件
- 伪静态
- 处理wordpress后台404问题(后台链接地址缺少 wp-admin)
- WordPress禁用文章修订及自动保存功能
- WordPress首页文章按最后修改时间排序
- nginx中的 http访问重定向设置
- 头像加载慢的问题
- 添加 favicon.ico
- 升级wordpress提示:另一更新正在进行
- 编辑wordpress的主题不能保存,提示:Scrape nonce check failed. Please try again.
- 升级提示: 正在执行例行维护,请一分钟后回来。
- 无法访问, 浏览器显示 ERR_TOO_MANY_REDIRECTS 错误
- 插入视频
- wordpress调试: 查看执行了哪些查询
- wordpress主题dux
- wordpress主题Kratos
- wordpress官方主题Twenty Fourteen
- wordpress缩略图
- wordpress插件WP Super Cache
- 使用mathjax
- 使用nginx
处理站点健康问题
wordpress后台, 工具,站点健康,处理列表中的问题。
常用插件
- WP Super Cache
- Autoptimize:可以压缩html,去掉注释。与 WP Super Cache 插件无冲突
- Bulk Delete:批量删除帖子等
- Companion Auto Update:本插件可自动更新所有插件、主题与 WordPress 内核。
- Disable XML-RPC-API:Lightweight plugin to disable XML-RPC API and Pingbacks,Trackbacks for faster and more secure website.
- Fixed Widget:使用 fixed widget小工具插件来创建粘性窗口小工具,这些页面在向上或向下滚动页面时会停留在可见的屏幕区域中,从而提高转化率。
- Redis Object Cache:A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, Credis, HHVM, replication, clustering and WP-CLI.
- Wordfence Security – Firewall & Malware Scan:安全插件
- WP Mail SMTP
- WPS Hide Login:通过更改登录URL并在未登录时阻止访问wp-login.php页面和wp-admin目录来保护您的网站
- Yet Another Related Posts Plugin (YARPP):Adds related posts to your site and in RSS feeds, based on a powerful, customizable algorithm.
- Google Analytics for WordPress by MonsterInsights:Google网站分析插件,这之前需要在 Google Analytics上添加网站。
- Theme Check:检查主题,如果用的是wordpress官方主题,实际上可以不考虑安装。
- WP Statistics: 统计分析
伪静态
vi /etc/nginx/sites-enabled/default, 代码片段:
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
#rewrite rules for wordpress
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
# for wordpress wp-admin 404 problem
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
纯净版:
location / {
try_files $uri $uri/ =404;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
配置wordpress, 自定义结构,如: http://xxx.com/%postname%/
处理wordpress后台404问题(后台链接地址缺少 wp-admin)
见伪静态部分, 注意增加的如下代码的位置,并不是和各条伪静态代码平级的:
# for wordpress wp-admin 404 problem
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
WordPress禁用文章修订及自动保存功能
vi wp-config.php
/** 禁用文章修订功能 */
define('WP_POST_REVISIONS', false);
/** 禁用自动保存功能 */
define('AUTOSAVE_INTERVAL', false);
SQL语句删除修订版本:
delete from wp_posts where post_type="revision";
SQL语句删除自动保存版本:
delete from wp_posts where post_type="post" and (post_status="auto-draft" or post_status="inherit");
删除页面并清空回收站.
WordPress首页文章按最后修改时间排序
编辑主题的 index.php, 在 while ( have_posts() ) 语句之前增加一行:
// orderby modified datetime
$posts = query_posts($query_string . '&orderby=modified');
while ( have_posts() ) :
nginx中的 http访问重定向设置
# for http request, redirect to https
server {
listen 80;
listen [::]:80;
server_name xxx.com;
return 301 https://$server_name$request_uri;
}
# https server
server {
#listen 80 default_server;
#listen [::]:80 default_server;
# SSL configuration
#
重启 nginx: service nginx restart
头像加载慢的问题
编辑wordpress主题的functions.php,在适当的位置(自己脑补)添加这段函数:
// v2ex gravatar
function replace_gravatar($avatar) {
$avatar = str_replace(array("//gravatar.com/", "//secure.gravatar.com/", "//www.gravatar.com/", "//0.gravatar.com/", "//1.gravatar.com/", "//2.gravatar.com/", "//cn.gravatar.com/"), "//cdn.v2ex.com/gr", $avatar);
return $avatar;}
add_filter( 'get_avatar', 'replace_gravatar' );
参考:
添加 favicon.ico
- 拷贝 favicon.ico 到网站根目录
- 在网页代码的与之间加入下面的代码:
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="Bookmark" href="/favicon.ico" />
升级wordpress提示:另一更新正在进行
数据库中删除相关记录:
delete FROM wp_options WHERE option_name='core_updater.lock';
编辑wordpress的主题不能保存,提示:Scrape nonce check failed. Please try again.
使用 Theme Editor 插件编辑主题文件.
升级提示: 正在执行例行维护,请一分钟后回来。
删除 wordpress根目录下的 .maintenance
本机: ubuntu系统自带http和socks全局代理:系统设置->网络->网络代理
无法访问, 浏览器显示 ERR_TOO_MANY_REDIRECTS 错误
如果使用了 cloudflare服务, 可能是 SSL/TLS 加密模式设置错误, 可以设置加密模式为完全.
插入视频
使用 <video>
标签. <video>
是 HTML 5 中的新标签。
<video>
标签的作用是在 HTML 页面中嵌入视频元素。
以下 HTML 片段会显示一段嵌入网页的 ogg、mp4 或 webm 格式的视频:
<video width="320" height="240" controls="controls">
<source src="movie.mp4" type="video/mp4" />
<source src="movie.ogg" type="video/ogg" />
<source src="movie.webm" type="video/webm" />
Your browser does not support the video tag.
</video>
wordpress调试: 查看执行了哪些查询
修改wp-config.php,添加如下代码:
/** 查看 wordpress 执行了哪些查询 */
define('SAVEQUERIES', true);
开启SAVEQUERIES会使WordPress将当前页面执行的sql查询保存到一个数组中,数组保存了每条查询的语句、调用该查询的函数以及执行时间。只要打印这个数组就能了解当前页面所有的sql查询了
打印数组,将下面的代码放到footer.php </body>
前面, 不用时注释掉
<?php
if (current_user_can('administrator')){
global $wpdb;
echo "<pre>";
print_r($wpdb->queries);
echo "</pre>";
}
?>
wordpress主题dux
收费主题, 最新版本可访问官网查询: https://themebetter.com/theme/dux
设置和修改主题前,建议:
- 删除 VPS本地缓存, 关闭缓存插件
- 删除cloudflare等cdn的缓存, 关闭cdn
主题设置
1.基本
- 网站底部信息: 可以考虑删除
- 关闭顶部Topbar (v4.1+):关闭
- 全站底部推广区:关闭
- 分享功能 (v1.8+):关闭
- 品牌文字:清空
2.SEO
- 首页关键字(keywords): 互联网工具等
- 首页描述(description): 互联网工具等
3.首页
- 最新发布 - 显示置顶文章 (v4.0+): 关闭
- 最新发布 - 标题右侧:清空
- 最新发布 - 标题:清空
- 公告模块:关闭
- 焦点图:关闭
4.列表
- 列表模式:图文模式,无特色图时自动转换为文字模式 (v1.6+)
- 分页无限加载页数:0
- 小部件:去掉 列表作者名 -微分类:关闭
- 微分类 - 首页:关闭
- 分类产品模版 - 二维码 (v5.2+):关闭
5.文章
- 点赞 (v4.2+):关闭
- 打赏 (v4.0+):关闭
- 文章来源:关闭
- 手机端不显示分享模块 (v2.0+):关闭
6.会员中心
- 开启会员中心:关闭
- 在首页公告栏显示会员模块:关闭
- 允许用户发布文章 (v1.6+):关闭
7.社交
- 网站顶部右上角关注本站:关闭
8.客服
- 不显示
主题文件修改
这款主题是存在很久了的商业主题, 自行优化应该没有必要甚至起到反作用, 进行有限的修改即可.
1. 停止版本检查
代码片段 settings/update.php:
<?php
function update_notifier_menu() {
//stop theme version check and update
return;
//...
//add_action('admin_menu', 'update_notifier_menu');
2.支持语法高亮
修改header.php.
参考https://highlightjs.org/ , 在网页模板的 <head>
与 </head>
之间加入类似下面的代码( /uploads/highlight/
或其他目录下要有对应定制的 css 和 js文件):
<link rel="stylesheet" href="/uploads/highlight/styles/a11y-dark.css">
<script src="/uploads/highlight/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<?php tb_xzh_head_var() ?>
</head>
推荐黑色系主题, 如 a11y-dark.
3.logo
- logo默认目录:
wp-content/themes/dux目录名/img/logo.png
, 在主题的设置中修改目录即可, 如/uploads/logo.png
- Logo 最大高:32px;建议尺寸:140*32px 格式:png
4.显示sql查询次数
在 footer.php 合适位置添加了如下代码,以显示wordpress查询数据库次数及查询耗时
<?php echo _hui('trackcode') ?>
<p>本页面执行了<?php echo get_num_queries(); ?>次查询,耗时<?php timer_stop(3); ?>秒</p>
</div>
</footer>
5.使用 MathJax 在网页中书写数学公式
在网页的header 部分加入对 MathJax 的引用,编辑 header.php 中添加如下代码:
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
</head>
菜单
建议设置菜单, 否则移动端显示有问题:菜单为空.
其他说明
- 参考官方文档
- 不用修改很多 php 代码调用为死代码, 可能会导致过度优化: php调用的次数可能反而增加
wordpress主题Kratos
主题官方网址: https://github.com/Vtrois/Kratos
使用wordpress插件 Theme Check检查该主题有很多问题.如果无法删除, 直接删除 wp-content/theme 文件夹下的该主题的文件夹即可.
1. 编辑pages/page-content.php, 删除相关代码, 首页不显示特色图像
修改后的 page-content.php 代码:
<?php
/**
* 文章列表
* @author Seaton Jiang <seaton@vtrois.com>
* @license MIT License
* @version 2020.03.14
*/
?>
<div class="article-panel">
<!--
<?php if (kratos_option('g_thumbnail', true)) { ?>
<div class="a-thumb">
<a href="<?php the_permalink(); ?>">
<?php post_thumbnail(); ?>
</a>
</div>
<?php } ?>
<div class="a-post <?php if (!kratos_option('g_thumbnail', true)) {
echo 'a-none';
} ?>">
-->
<!--replace by the following line -->
<div class="a-post a-none">
<div class="header">
<?php $category = get_the_category();
echo '<a class="label" href="' . get_category_link($category[0]->term_id) . '">' . $category[0]->cat_name . '<i class="label-arrow"></i></a>'; ?>
<h3 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="content">
<p><?php echo wp_trim_words(get_the_excerpt(), 260); ?></p>
</div>
</div>
<div class="a-meta">
<span class="float-left d-none d-md-block">
<span class="mr-2"><i class="kicon i-calendar"></i><?php echo get_the_date('Y年m月d日'); ?></span>
<span class="mr-2"><i class="kicon i-comments"></i><?php comments_number('0', '1', '%');
_e('条评论', 'kratos'); ?></span>
</span>
<span class="float-left d-block">
<span class="mr-2"><i class="kicon i-hot"></i><?php echo get_post_views();
_e('点热度', 'kratos'); ?></span>
<span class="mr-2"><i class="kicon i-good"></i><?php if (get_post_meta($post->ID, 'love', true)) {
echo get_post_meta($post->ID, 'love', true);
} else {
echo '0';
}
_e('人点赞', 'kratos'); ?></span>
</span>
<span class="float-right">
<a href="<?php the_permalink(); ?>"><?php _e('阅读全文', 'kratos'); ?><i class="kicon i-rightbutton"></i></a>
</span>
</div>
</div>
2.footer.php
去掉相关不需要的内容:
<?php
/**
* 主题页脚
* @author Seaton Jiang <seaton@vtrois.com>
* @license MIT License
* @version 2020.03.17
*/
?>
<div class="k-footer">
<div class="f-toolbox">
<div class="gotop <?php if (kratos_option('s_wechat', false)) {
echo 'gotop-haswechat';
} ?>">
<div class="gotop-btn">
<span class="kicon i-up"></span>
</div>
</div>
<?php if (kratos_option('s_wechat', false)) { ?>
<div class="wechat">
<span class="kicon i-wechat"></span>
<div class="wechat-pic">
<img src="<?php echo kratos_option('s_wechat_url', get_template_directory_uri() . '/assets/img/wechat.png'); ?>">
</div>
</div>
<?php } ?>
<div class="search">
<span class="kicon i-find"></span>
<form class="search-form" role="search" method="get" action="<?php echo home_url('/'); ?>">
<input type="text" name="s" id="search" placeholder="<?php _e('搜点什么呢?', 'kratos'); ?>" style="display:none" />
</form>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-12 text-center">
<p class="social">
<?php
$social = array('s_sina', 's_bilibili', 's_coding', 's_gitee', 's_twitter', 's_telegram', 's_linkedin', 's_youtube', 's_github', 's_stackflow', 's_email');
foreach ($social as $social) {
if (kratos_option($social)) {
echo '<a target="_blank" rel="nofollow" href="' . kratos_option($social . '_url') . '"><i class="kicon i-' . str_replace("s_", "", $social) . '"></i></a>';
}
}
?>
</p>
<?php
$sitename = get_bloginfo('name');
echo '<p>' . kratos_option('s_copyright', 'COPYRIGHT © 2020 ' . $sitename . '. ALL RIGHTS RESERVED.') . '</p>';
/**
echo '<p>THEME <a href="https://github.com/vtrois/kratos" target="_blank" rel="nofollow">KRATOS</a> MADE BY <a href="https://www.vtrois.com/" target="_blank" rel="nofollow">VTROIS</a></p>';
if (kratos_option('s_icp')) {
echo '<p><a href="http://www.beian.miit.gov.cn/" target="_blank" rel="nofollow">' . kratos_option('s_icp') . '</a></p>';
}
if (kratos_option('s_gov')) {
echo '<p><a href="' . kratos_option('s_gov_link', '#') . '" target="_blank" rel="nofollow" ><i class="police-ico"></i>' . kratos_option('s_gov') . '</a></p>';
}
*/
if (kratos_option('seo_statistical')) {
echo '<p>' . kratos_option('seo_statistical') . '</p>';
}
?>
</div>
</div>
</div>
</div>
<?php wp_footer(); ?>
</body>
</html>
3.wordpress后台Kratos主题设置
全站配置
- 开启 Font Awesome 字体
- 开启静态资源加速(CSS、JS、Font): 猫云
- 开启 Gravatar 头像加速
4.顶部配置
顶部样式:颜色导航. 主色可以考虑为蓝色设置为:
#3b5999
蓝色也是Facebook的主要颜色,因为扎克伯格是个色盲.
5.支持语法高亮
参考https://highlightjs.org/, 在网页模板的
与之间加入类似下面的代码: <link rel="stylesheet" href="/uploads/highlight/styles/vs.css">
<script src="/uploads/highlight/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
wordpress官方主题Twenty Fourteen
该主题下, 修改文章的内容宽度:通过修改 style.css完成。
1.修改文字宽度,该宽度受限于页面宽度,显示时最多为页面宽度
默认的文字宽度只有474px,修改该宽度,比如 4740px:
.page-content {
margin: 0 auto;
max-width: 4740px;
}
.page-content {
margin-bottom: 48px;
}
2.修改页面宽度占满页面, 在 style.css 中添加下边代码,粘贴到最后就可以了:
.site,
.site-header {
max-width: 100%;
}
wordpress缩略图
添加图片时的数据库变化
比如添加了 github.png, 会在如下表中添加信息:
wp_posts 中增加一个 post, 信息类似如下:
- ID :41
- post_author :1
- post_date : 2020-04-25 18:21:01
- post_date_gmt: 2020-04-25 10:21:01
- post_content
- post_title: github, 不带文件扩展名的图片文件名
- post_excerpt
- post_status:inherit
- comment_status: open
- ping_status: closed
- post_password
- post_name:github
- to_ping
- pinged
- post_modified:2020-04-25 18:21:01
- post_modified_gmt:2020-04-25 10:21:01
- post_content_filtered
- post_parent:0
- guid : https://feedory.com/wp-content/uploads/2020/04/github.png ,这里存放图片地址
- menu_order:0
- post_type :attachment
- post_mime_type: image/png
- comment_count:0
wp_postmeta表中增加对应 post_id的类似如下信息:
前一个为 meta_key, 后一个为 meta_value,
- _wp_attached_file: 2020/04/github.png , 默认放到了wordpress的uploads目录
- _wp_attachment_metadata:图片本身的元数据
- views:1
直接在数据库中修改文件存储路径是不行的, 生成的路径是 /wp-content/uploads/uploads/thumbnails/github.png
, 所以这个路径是由wordpress拼接的, 所以缩略图用到的图片必须手动从wordpress后台上传, 图片文件夹默认是固定死的, 用其他文件夹的图片或外链的图片会比较麻烦, 实际上手动上传图片后, 可以通过图片名和图片类型指定特色图像.
update wp_postmeta set meta_value='/uploads/thumbnails/github.png' where meta_key='_wp_attached_file' and post_id=41;
手动批量上传图片后,wp-content/uploads
目录下会自动生成缩略图.
在数据库中为帖子指定缩略图
要帖子13 的缩略图对应上述的41, 插入或修改 wp_postmeta 中的记录, meta_key的值为 _thumbnail_id
, meta_value的值为图片对应的 post_id, post_id为帖子的id.
数据库中的结构
+---------+---------+---------------+--------------+
| meta_id | post_id | meta_key | meta_value |
+---------+---------+---------------+--------------+
| 83 | 13 | _thumbnail_id | 41 |
+---------+---------+---------------+--------------+
插入语句:
insert into wp_postmeta(post_id,meta_key,meta_value) values(13,'_thumbnail_id',41);
wordpress插件WP Super Cache
WP Super Cache 插件提供两种主要的缓存模式
- 简单模式
不推荐。虽然在插件安装后默认推荐使用这样的方式,是因为启用这个缓存模式是最简单的,不需要服务器配置和规则,只要能够正常运行 WordPress 就可以了,因为这种缓存模式主要使用由 php 提供缓存。
- 专家模式
这是最快的方式,通过 Mod_Rewrite 模块向用户提供 WP Super Cache 生成的缓存文件,这样就直接绕过 WordPress php 从数据库中查询,可以说是速度杠杠的,如果你是 Apache 服务器则需要修改.htaccess 文件,Nginx 服务器也需要添加 Nginx 规则。
这种模式可以通过命令行删除缓存文件, 达到更新缓存文件的目的.
专家模式设置
参考: Nginx | WordPress.org 的 WP Super Cache Rules 部分, wordpress后台设置为专家模式, 同时nginx的server配置文件添加:
# refer to https://wordpress.org/support/article/nginx/#wp-super-cache-rules ===>
# WP Super Cache rules.
# Designed to be included from a 'wordpress-ms-...' configuration file.
set $cache_uri $request_uri;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $cache_uri 'null cache';
}
if ($query_string != "") {
set $cache_uri 'null cache';
}
# Don't cache uris containing the following segments
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 $cache_uri 'null cache';
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
set $cache_uri 'null cache';
}
# Use cached or actual file if they exists, otherwise pass request to WordPress
location / {
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?$args ;
}
# <=== refer to https://wordpress.org/support/article/nginx/#wp-super-cache-rules
如果网站启用了 https
, 最后几行替换为:
location / {
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index-https.html $uri $uri/ /index.php?$args ;
}
这里 try_files
对应的代码段放在 location /
里, 替换原来的 try_files
对应的值.
生成的缓存内容在类似目录下: ~/wp-content/cache/supercache/xxxx.com
, 删除该目录下的所有文件相当于清空了缓存.
参考
使用mathjax
1.网页侧MathJax设置
在网页的header 部分加入对 MathJax 的引用
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
如果用 Sublime Text 3, 直接在 MarkDown Preview 插件中设置MathJax就可以了.
参考:http://docs.mathjax.org/en/latest/configuration.html
2.python侧设置
安装 Math extension for Python-Markdown
pip install python-markdown-math
在python中使用, extensions中加入 'mdx_math'
:
import markdown
...
html_temp = markdown.markdown(code_str,
extensions=['markdown.extensions.extra',
'markdown.extensions.codehilite',
'markdown.extensions.tables',
'markdown.extensions.toc',
'mdx_math',
DelInsExtension()])
3.MathJax 语法
MathJax中的公式排版有两种方式,inline和displayed。inline表示公式嵌入到文本段中,displayed表示公式独自成为一个段落。
The default math delimiters are $$...$$ and \[...\] for displayed mathematics, and \(...\) for in-line mathematics.
代码:
test(行内,可以设置为前后加上$): \( f(x)=3 \times x \)
test(独立段落):$$f(x)=3 \times x$$
$$f(x|\mu,\sigma)=\frac{1}{\sqrt{2\pi}\sigma}exp(-\frac{(x-\mu)^2}{2\sigma^2})$$
显示效果(如果是刚刚部署 MathJax, 可能要等一段时间才能刷新出来):
test(行内): (f(x)=3 \times x)
test(独立段落):
$$f(x)=3 \times x$$ $$f(x|\mu,\sigma)=\frac{1}{\sqrt{2\pi}\sigma}exp(-\frac{(x-\mu)^2}{2\sigma^2})$$
参考:
- http://mlworks.cn/posts/introduction-to-mathjax-and-latex-expression/
- http://blog.csdn.net/ethmery/article/details/50670297
- http://docs.mathjax.org/en/latest/start.html#tex-and-latex-input
- 在Markdown中输入数学公式(MathJax)
分式(分号) fractions
\frac{分子}{分母}
效果: (\frac{分子}{分母})
特殊符号
符号 | 写法 |
---|---|
(\partial) | \partial |
使用nginx
任意子域名跳转到指定域名
比如, 任何 *.yinhe.co 跳转到 yinhe.co, 修改 nginx配置文件, 在server段内(不是新建一个 server段) 添加类似如下的301跳转:
server{
index index.php;
#server_name _;
server_name yinhe.co;
if ($host != 'yinhe.co' ) {
return 301 https://yinhe.co$request_uri;
}
}
使用 alias 添加别名访问目录
注意 alias后面必须要用“/”结束,否则会找不到文件:
location ^~ /uploads/ {
alias /L2W_yinhe/uploads/;
}
以上配置, 会在访问类似 https://yinhe.co/uploads/logo.png
的文件时, 访问VPS上的 /L2W_yinhe/uploads/logo.png
文件
性能优化
参考 Help the World by Healing Your NGINX Configuration 优化, 部分优化项:
- 字体和图像设置较长的缓存过期时间
修改具体域名的nginx配置, 如下配置指示客户端浏览器将字体和图像在本地缓存中保留一个月:
location ~* \.(?:jpg|jpeg|gif|png|ico|woff2)$ {
expires 1M;
add_header Cache-Control "public";
}
需要注意的是,字体有很多格式(eot|ttf|otf|woff|svg
), 所以可以修改为:
location ~* \.(?:jpg|jpeg|gif|png|ico|woff2|eot|ttf|otf|svg)$ {
expires 1M;
add_header Cache-Control "public";
}
2.减少和优化日志记录
2.1 修改具体域名的nginx配置, 禁用页面资源请求的记录:
location ~* \.(?:jpg|jpeg|gif|png|ico|woff2|js|css)$ {
access_log off;
}
修改版, 增加了资源类型:
location ~* \.(?:jpg|jpeg|gif|png|ico|woff2|eot|ttf|otf|svg|js|css)$ {
access_log off;
}
2.2 不记录请求成功的日志, 这里用默认combined格式记录日志, 编辑 /etc/nginx/nginx.conf
#access_log /var/log/nginx/access.log;
map $status $loggable {
~^[23] 0;
default 1;
}
access_log /var/log/nginx/access.log combined buffer=512k flush=1m if=$loggable;
未分类
无法上传文件,提示 您点击的链接已过期。
- sudo vi /etc/php/7.4/fpm/php.ini
post_max_size = 100M
upload_max_filesize = 100M
重启php: sudo service php7.4-fpm restart
2.修改nginx配置文件
# pass PHP scripts to FastCGI server
location ~ .*\.php(\/.*)*$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
client_max_body_size 100M;
}
删除失败:请求的主题不存在。
删除 /wp-content/themes 下的主题文件夹.
可能的原因: zip文件含有-
,.
等特殊符号。
插件 WP Statistics
该插件貌似和其他一些插件有冲突,数据显示差异很大。放弃。
GeoIP无法更新,手动更新:
参考 https://github.com/wp-statistics/GeoLite2-Country 从 https://raw.githubusercontent.com/wp-statistics/GeoLite2-Country/master/GeoLite2-Country.mmdb.gz 手动下载文件,解压上传到 wp-content/uploads/wp-statistics/GeoLite2-Country.mmdb
参考 https://github.com/wp-statistics/GeoLite2-City 从 https://github.com/wp-statistics/GeoLite2-City/raw/master/GeoLite2-City.mmdb.gz,手动下载文件,解压上传
© Licensed under CC BY-NC-SA 4.0价值投资不能保证我们盈利, 但价值投资给我们提供了通向成功的唯一机会。——巴菲特