簡體   English   中英

如何刷新 AMP 緩存?

[英]How to refresh AMP Cache?

我有一個帶有 AMP 的文章頁面(在子域上)。 現在我在一篇文章中做了一些改動。 如何重新加載這個緩存的 AMP(子)頁面?

普通版: https : //www.example.com/this-is-a-article-999

AMP 版本: https : //amp.example.com/this-is-a-article-999

我執行以下步驟:

1.我已經在我的服務器上安裝了 openssl

2.然后我生成了兩個密鑰

openssl genrsa 2048 > 私鑰.pem

openssl rsa -in private-key.pem -pubout >public-key.pem

3.我將公鑰復制到子域(= AMP頁面)並將其重命名為“apikey.pub”

因此可以通過瀏覽器訪問公鑰: https : //amp.example.com/apikey.pub

4.然后我創建了更新緩存請求如下:

獲取帶有“date +%s”的時間戳

echo -n >url.txt '/update-cache/c/s/amp.example.com/this-is-a-article-999?amp_action=flush&amp_ts=1526997689' cat url.txt | openssl dgst -sha256 -sign private-key.pem >signature.bin

5.我用公鑰驗證簽名:

openssl dgst -sha256 -signature signature.bin -verify public-key.pem url.txt

我收到以下錯誤:==>驗證失敗(!!!)

在第3步,公鑰的位置是錯誤的。 正確的應該是: https://amp.example.com/.well-known/amphtml/apikey.pub : https://amp.example.com/.well-known/amphtml/apikey.pub

驗證問題似乎在第 4 步,因為在單行上調用了 2 個命令並生成無效輸出。

解決方案是將其分為兩部分:

echo -n >url.txt '/update-cache/c/s/amp.example.com/this-is-a-article-999?amp_action=flush&amp_ts=1526997689' 
cat url.txt | openssl dgst -sha256 -sign private-key.pem >signature.bin

或在 2 個命令之間添加 & :

echo -n > url.txt '/update-cache/c/s/amp.example.com/this-is-a-article-999?amp_action=flush&amp_ts=1526997689' & cat url.txt | openssl dgst -sha256 -sign private-key.pem > signature.bin

完整的序列變成了這樣:

openssl genrsa 2048 > private-key.pem
openssl rsa -in private-key.pem -pubout > public-key.pem
echo -n > url.txt '/update-cache/c/s/amp.example.com/this-is-a-article-999?amp_action=flush&amp_ts=1526997689'
cat url.txt | openssl dgst -sha256 -sign private-key.pem > signature.bin
openssl dgst -sha256 -signature signature.bin -verify public-key.pem url.txt

輸出如下:

openssl dgst -sha256 -signature signature.bin -verify public-key.pem url.txt
Verified OK

另一件事情是,在生成簽名后,必須使用Base64網絡安全變體將其附加到amp_url_signature參數上的 URL。

最后,請務必檢查文檔的參數部分並根據AMP Cache URL Format生成URL

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM