作者归档:wmbk

WordPress 优化 – 使用 Crontab 取代 WP-Cron

简单来说,WordPress 默认的 Cron 触发依赖于网站访问而启动,并不是真正的“计划任务”,在性能和可靠性等多个方面都不理想

因此,我会使用 Ubuntu 下的 Crontab 来取代它,当然,在 Windows 下也可以使用任务计划达到同样的效果

首先,我们需要停用 WP-Cron,在 WordPress 安装目录的 wp-config.php 内添加:

define('DISABLE_WP_CRON', true);

然后使用 crontab -e 进入计划任务编辑,第一次进入时需要选择编辑器,我习惯选择 Nano(第一个选项)

进入编辑界面后,输入以下任务:

*/10 * * * * curl http://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
<span class="hljs-comment"># 将 example.com 替换为你的域名</span>

From https://easyengine.io/tutorials/wordpress/wp-cron-crontab

在 Windows 下,可以新建计划任务,运行以下命令以达到同样效果:

powershell "Invoke-WebRequest http://example.com/wp-cron.php?doing_wp_cron"

同时,我们会遇到一个问题,即任何人都可以访问 wp-cron.php,这可能会被利用进行 DOS 攻击

因此,我选择用一条 CloudFlare 规则,限制只允许服务器 IP 访问。当符合规则时阻止访问:

(http.request.full_uri contains "wp-cron.php" and ip.src ne 192.168.0.1) #以服务器 IP 取代 192.168.0.1

最后,记得在你的 CDN 内把 wp-cron.php 设置为动态(不缓存)

 

如何在没有微软商店的情况下安装 NVIDIA 控制面板

前些天在安装 NIVIDIA 驱动后发现没有一并安装 NVIDIA Control Panel(英伟达控制面板),问题在于我停用了 Windows Update,而 NVIDIA 控制面板又是从微软商店安装的,在停用 Update 的同时也把商店停用了

原因

英伟达在 Windows10 后推出 DCH 版驱动后

My Windows 10 PC has NVIDIA DCH Display Drivers installed. Can I download and install NVIDIA Standard Display Drivers from NVIDIA.com?

Yes, you can locate and download the driver through the Advanced Driver Search.

(From https://nvidia.custhelp.com/app/answers/detail/a_id/4777/)

其中的 Advanced Driver Search 在新版驱动搜索网页已经消失(英伟达已经不再更新标准版驱动了)

解决方法

首先打开第三方的微软商店下载器,输入 NVIDIA Control Panel 的网址,即 https://apps.microsoft.com/detail/9nf8h0h7wmlt

加载完成后可以看到列表如下:

Capture of store.rg-adguard.net

右键保存最新的版本,这里以 NVIDIACorp.NVIDIAControlPanel_8.1.968.0_x64__56jybvy8sckqj.appx 为例

下载后打开 PowerShell,执行命令(当然文件名是会随着更新变得)

Add-AppxPackage .\NVIDIACorp.NVIDIAControlPanel_8.1.968.0_x64__56jybvy8sckqj.Appx 

完成后右键桌面如无意外即可看到 NVIDIA 控制面板的选项

 

解决 Windows 系统下安装 tflite-support 时的报错

最近因为一些原因需要用到 tflite-support 这个库,但是当使用 pip 安装时出现错误,具体错误如下:

      C:\Users\xxxxx\AppData\Local\Programs\Python\Python3x\lib\site-packages\setuptools\command\build_py.py:202: SetuptoolsDeprecationWarning:     Installing 'tflite_support.flatbuffers' as data is deprecated, please list it in `packages`.
          !!
          ############################
          # Package would be ignored #
          ############################
          Python recognizes 'tflite_support.flatbuffers' as an importable package,
          but it is not listed in the `packages` configuration of setuptools.

          'tflite_support.flatbuffers' has been automatically added to the distribution only
          because it may contain data files, but this behavior is likely to change
          in future versions of setuptools (and therefore is considered deprecated).

          Please make sure that 'tflite_support.flatbuffers' is included as a package by using
          the `packages` configuration field or the proper discovery methods
          (for example by using `find_namespace_packages(...)`/`find_namespace:`
          instead of `find_packages(...)`/`find:`).

          You can read more about "package discovery" and "data files" on setuptools
          documentation page.
      !!

        check.warn(importable)
      copying tflite_support\metadata_schema.fbs -> build\lib.win-amd64-cpython-310\tflite_support
      creating build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
      copying tflite_support\flatbuffers\__init__.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
      copying tflite_support\flatbuffers\builder.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
      copying tflite_support\flatbuffers\compat.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
      copying tflite_support\flatbuffers\encode.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
      copying tflite_support\flatbuffers\number_types.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
      copying tflite_support\flatbuffers\packer.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
      copying tflite_support\flatbuffers\table.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
      copying tflite_support\flatbuffers\util.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
      running build_ext
      building '_pywrap_codegen' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> tflite-support

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

这是因为 tflite-support 没有官方的 Windows 发行版,因此在 Windows 系统上需要自行编译

从输出可以看到:error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/

即本地没有 C++编译器,因此我们只需安装 C++编译器即可:https://visualstudio.microsoft.com/zh-hant/visual-cpp-build-tools

在安装时只需要勾选 使用 C++的桌面开发 ,无需勾选其余项目

在安装后使用命令 pip install tflite-support 重新安装即可

 

AdAway – 安卓老牌开源广告屏蔽器

AdAway 是一个开源的安卓广告拦截工具,利用修改系统的 hosts 文件实现屏蔽广告

当设备进行 DNS 查询时,系统会以 hosts 文件优先,而 AdAway 将与广告联盟的域名解析到 0.0.0.0 或 127.0.0.1,从而阻断广告请求

由于需要修改 hosts,因此需要 ROOT 权限,软件同时也提供无需 ROOT 的 VPN 版本

该软件能够阻挡大多数应用和网页的广告联盟,如 AdSense, 穿山甲

类似的软件还有 AdGuard, Blokada 等

软件设置

AdAway 官网: https://adaway.org

下载并安装软件后可以选择使用 ROOT 模式或 VPN 模式,VPN 模式会增加耗电量,所以尽可能选择 ROOT 模式

点击 ROOT 模式后会调出 SU 授权框,取决于你用的 SU 管理器(Magisk, KernelSU…),点击同意

A capture of AdAway main screen

到软件主画面可以看到默认已经有三个广告拦截规则。此时打开网页基本不会看到广告,不过为了达到更好的效果,我还额外添加了广告规则

点击类似书签的按钮再点击加号即可添加规则,我添加了以下的规则:

https://divested.dev/hosts

https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts

最后,这类通过 DNS 过滤实现屏蔽广告的方案还是有漏网之鱼的

比如 Youtube 的广告和视频是在同一个域名(屏蔽广告的同时也屏蔽了视频)

要屏蔽 Youtube 这类网站的广告只能靠第三方 APP 或者浏览器插件了

 

 

加固 WordPress – 避免暴力破解密码

WordPress 作为一个市场占有量最高的 CMS,其登录页面 wp-login.php 每天经受不少的爆破尝试,以我的博客为例,在短短 24 小时内就被(尝试)爆破了 160 次

要避免这个问题很简单,我主要用了以下两种方式

限制登录次数

有很多插件可以实现限制登录次数,这里以Limit Login Attempts Reloaded这个插件为例

插件分为免费以及付费版,不过免费版够用了

安装并启用插件,转到插件设置页面,可以设置尝试错误密码多少次后拦截

以下是我的设置:

After a specific IP address fails to log in 4 times, a lockout lasting 20 minutes is activated. If additional failed attempts occur within 24 hours and lead to another lockout, once their combined total hits 4, the 20 minutes duration is extended to 24 hours. The lockout will be lifted once 24 hours have passed since the last lockout incident.

添加验证码

常见的验证码有不少,Cloudflare Turnstile, reCAPTCHA, hCaptcha 等等

我比较习惯用老牌的 reCAPTCHA

创建 reCAPTCHA ,reCAPTCHA 类型可选 V2, V3 其中 V2 需要手动点击,而 V3 为无感验证

创建后会获得网站密钥及密钥,回到网站安装Advanced Google reCAPTCHA插件

启用插件后找到插件设置,填入 Captcha Site Key, Captcha Secret Key,输入后会弹出 Verify Captcha 按钮,验证一次后即可保存设置

找到 Where To Show 菜单,这里可以验证码展示的位置,我选择关闭评论的验证码(因为我会手动筛选评论,而且不希望被 JS 拖慢网站速度)

 

最后,不要用 admin 这类的弱密码…

写在独立博客三周年

不知不觉博客已经运行三年了,三年前创建这个博客的原因主要是想靠广告赚钱,到真的搭了博客后才发现博客是一门亏钱的生意…

无论如何,这个博客就断断徐徐的运行到了现在

博客的时间线:

  • 2022.08 初代博客,使用 Typecho 及 Freewind 主题
  • 2023.11 将博客搬到 NAS 内,用 Warp 穿透
  • 2024.07 从 NAS 搬到 Github+Vercel 以及更换到 Hexo+Volantis
  • 2025.08 从 Hexo 又搬到 WordPress

在博客三周年之际,从用了一年多的 Hexo 又换成 WordPress,下一次大改可能又是一年后

在换成 WP 后 Google 的收录又回来了,而 Bing 还是久久不更新

截至今天,网站的 DR 为 26

流量来源

在 7 天内,来自搜索引擎(Google 和 Bing)的流量最高,共为 30UV,其次为各博客聚合网站

  • 开往 10UV
  • 十年之约 13UV
  • 博友圈 3UV
  • 无聊湾 2UV
  • BlogFinder 1UV
  • 博客说 1UV
  • BlogWe 1UV

以及各友情链接带来共 22UV

未来规划

  • 做好 SEO
  • 获取更多 Backlinks
  • 发多点文章
  • 降低成本

我认为,在 SEO 中反向链接是非常重要的一点,即便不能提升我的 Page rank,也能带来一定数量的访客

目前我获得 backlink 的主要方法是友情链接…以及评论,不过我同意一个观点:如果一个链接很容易就能获得,那它就没啥价值

无论如何,接下来尝试做点 SEO 吧

 

Matomo 统计绕过 Adblock 拦截

大部分 Adblock 默认会把 matomo.js 封锁,所以我们需要将文件”改名”
把 js 以及 php 代理,这里以 WordPress 安装的 Matomo 为例
如果你不是以 WP 安装,记得域名中也不要包含 matomo, tracking 这类关键字
Apache .htaccess

RewriteEngine On 
RewriteRule ^wp-content/plugins/app/class$ wp-content/uploads/matomo/matomo.js [L] 
RewriteRule ^wp-content/plugins/app/class\.php$ wp-content/plugins/matomo/app/matomo.php [L]

另外`matomo.php?action_name=`也会被拦截,所以需要从默认的 GET 请求更换成 POST 请求,这里是修改后的代码

<script data-cfasync="false">
(function () {
function initTracking() {
var _paq = window._paq = window._paq || [];
_paq.push(['setRequestMethod', 'POST']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
_paq.push(['alwaysUseSendBeacon']);
_paq.push(['setTrackerUrl', "\/\/example.site\/wp-content\/plugins\/app\/class.php"]);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript';
 g.async=true;
 g.src="\/\/example.site\/wp-content\/plugins\/app\/class";
 s.parentNode.insertBefore(g,s);
}
if (document.prerendering) {
	document.addEventListener('prerenderingchange', initTracking, {once: true});
} else {
	initTracking();
}
})();
</script>