我需要对所有网站执行 curl -IL 操作,并且每 24 小时执行一次 cron 任务或其他操作,以便 fastcgi 可以缓存所有页面维果
除非我卷曲网页,否则缓存不会命中,因此我需要一些可以卷曲网站上所有可用网页的东西。
就像你在下面看到的一样:
root@ubuntu-s-1vcpu-1gb-amd-sfo3-01:~# curl -IL https://www.example.com
HTTP/2 200
date: Thu, 23 Feb 2023 10:31:44 GMT
content-type: text/html; charset=UTF-8
link: <https://www.example.com/wp-json/>; rel="https://api.w.org/"
link: <https://www.example.com/wp-json/wp/v2/pages/16274>; rel="alternate"; type="application/json"
link: <https://www.example.com/>; rel=shortlink
x-fastcgi-cache: HIT
cf-cache-status: DYNAMIC
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=2K%2BxMLMMrvGpe%2FdpG38gU%2FKaBPBAL5I3rYNL5ATQ65wPM2qMnQmaCe2jLx88N%2B%2BHeUw1RRI5EnrYh9%2F6P5fj7xAipg%2FnOxi4IV8e4IqPWMyANW9JnKndXGfBZw0r3LtF1IEl"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 79df4b241af32f15-LAX
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
答案1
这就是您使用的 WordPress。我相信有更好的方法来预热缓存:https://de.wordpress.org/plugins/search/cache+warm/
使用以下代码创建 warmup.sh 之类的文件
#!/bin/bash
# URL of main Sitemap
sitemap_url="https://www.vgopromo.com/wp-sitemap.xml"
# Extract all Sitemap URLs
sitemap_urls=$(curl -s "$sitemap_url" | grep -oP '(?<=<loc>)[^<]+')
# Loop over and retrieve the individual URLs
for sitemap in $sitemap_urls; do
urls=$(curl -s "$sitemap" | grep -oP '(?<=<loc>)[^<]+')
for url in $urls; do
curl -IL "$url"
done
done
这将完成您所请求的。
您还可以使用 Cronjob 来运行此文件。
# Example: At minute 15 past every hour.
15 */1 * * * /bin/bash /root/warmup.sh
编辑
此修改后的代码添加了定义子域的选项。
#!/bin/bash
# Array of Subdomains, just extend in same princip
subdomains=("www" "subdomain_2")
# Loop over Subdomains and retrieve URLs
for subdomain in "${subdomains[@]}"; do
sitemap_url="https://$subdomain.vgopromo.com/wp-sitemap.xml"
sitemap_urls=$(curl -s "$sitemap_url" | grep -oP '(?<=<loc>)[^<]+')
for sitemap in $sitemap_urls; do
urls=$(curl -s "$sitemap" | grep -oP '(?<=<loc>)[^<]+')
for url in $urls; do
curl -IL "$url"
done
done
done
我个人建议这样做。使其与多个项目兼容
#!/bin/bash
# Array of Domains, just extend in same princip
domains=("https://www.vgopromo.com/wp-sitemap.xml" "https://example.vgopromo.com/wp-sitemap.xml")
# Loop over Domains and retrieve URLs
for domain in "${domains[@]}"; do
sitemap_url="$domain"
sitemap_urls=$(curl -s "$sitemap_url" | grep -oP '(?<=<loc>)[^<]+')
for sitemap in $sitemap_urls; do
urls=$(curl -s "$sitemap" | grep -oP '(?<=<loc>)[^<]+')
for url in $urls; do
curl -IL "$url"
done
done
done