Pages that support AMP are cached by the provider on the Google side, and the cached pages are delivered from there, achieving high-speed web pages. So the question is how to update the cached page. This article describes how to manually update the AMP cache using a mechanism called update-cache. In WordPress etc., when you update the article, you need to update the cache of the AMP page as well.
Create a private key and public key locally.
$ openssl genrsa 2048 > private-key.pem
$ openssl rsa -in private-key.pem -pubout > apikey.pub
Place the public key on the server. Please place it in the following location.
/Document root/.well-known/amphtml/apikey.pub
You need to add "text / plain" to the content type in the web server configuration file. This is the setting method for Nginx.
/etc/nginx/mime.types
types {
#Add to the end
text/plain pub;
}
nginx reboot
$ sudo systemctl restart nginx
Make sure that the public key "apikey.pub" is accessible and that the content type is "text / plain".
$curl -I https://example.com/.well-known/amphtml/apikey.pub
If the HTTP part and content-type part are displayed as shown below, you can set them without any problem.
HTTP/2 200
content-type: text/plain
Originally, refer to Google's official document "Update AMP content" and update using a manually created key. -I make a cache request, but I'm grateful to use it because there is a predecessor who creates a series of flows with a shell script. https://github.com/sizaki30/google-amp-update-cache
After downloading the script, change the private key location.
# private_Change the key part.
private_key='/Specify the location of the private key with the full path/private-key.pem'
Upload the script anywhere on the server.
Run the script, specifying the URL of the page for which you want to update the AMP cache. (It is recommended to quote the URL.) If "OK" is displayed, the update-cache request is successful.
$sudo sh google-amp-update-cache.sh 'https://example.com/test.html'
OK
Recommended Posts