简体   繁体   English

使用/ update-cache请求更新AMP页面

[英]Using /update-cache requests to update AMP pages

Trying to use /update-cache/ requests to update some AMP pages, but i'm getting 403 errors. 尝试使用/ update-cache / requests来更新一些AMP页面,但是我收到403错误。

Removed the opening part/protocol from the urls since i don't have the reputation to post this many links, but everything is https. 从网址中删除了开放部分/协议,因为我没有发布这么多链接的声誉,但一切都是https。

I have a page at: www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert-biohajklinika-szepsegapolas-egeszseg/amp 我的页面是:www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert-biohajklinika- szepsegapolas-egeszseg / AMP

From the AMP cache: www-qponverzum-hu.cdn.ampproject.org/c/s/www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert-biohajklinika-szepsegapolas-egeszseg/amp 来自AMP缓存:www-qponverzum-hu.cdn.ampproject.org/c/s/www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas -5000-FT-helyett-2500-FT-ERT-biohajklinika-szepsegapolas-egeszseg /安培

I've been following the documentation at developers.google.com/amp/cache/update-ping 我一直在关注developers.google.com/amp/cache/update-ping的文档

If i make an /update-ping request, it seems to work fine, returns a 200 no content response, but due to the high amount of urls/pages we would like to use /update-cache since it allows for a higher request rate. 如果我发出/ update-ping请求,它似乎工作正常,返回200无内容响应,但由于我们想要使用/更新缓存的大量网址/页面,因为它允许更高的请求率。

I've created a private and public RSA key and made the public key acessible at www.qponverzum.hu/.well-known/amphtml/apikey.pub 我创建了一个私有和公共RSA密钥,并在www.qponverzum.hu/.well-known/amphtml/apikey.pub上提供了公钥。

I've been trying to use the following php code to generate the update-cache url 我一直在尝试使用以下php代码来生成update-cache url

$ampBaseUrl = "https://www-qponverzum-hu.cdn.ampproject.org";
$signatureUrl = '/update-cache/c/s/www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert-biohajklinika-szepsegapolas-egeszseg/amp?amp_action=flush&_ts='.time();

// opening the private key
$pkeyid = openssl_pkey_get_private("file://private-key.pem");

// generating the signature
openssl_sign($signatureUrl, $signature, $pkeyid)

// urlsafe base64 encoding
$signature = urlsafe_b64encode($signature);

// final url for updating
$ampUrl = $ampBaseUrl.$signatureUrl."&amp_url_signature=".$signature;

The urlsafe_b64encode function I'm using: 我正在使用的urlsafe_b64encode函数:

function urlsafe_b64encode($string) {
    return str_replace(array('+','/','='),array('-','_',''), base64_encode($string));
}

$ampUrl ends up looking like this: https://www-qponverzum-hu.cdn.ampproject.org/update-cache/c/s/www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast-mikrokameras-hajdiagnosztika-hajhagyma-es-fejborvizsgalattal-tanacsadas-5000-ft-helyett-2500-ft-ert-biohajklinika-szepsegapolas-egeszseg/amp?amp_action=flush&amp_ts=1500362660&amp_url_signature=NjTCnmqUGpMY_CokGxchoczSOxnTLQvcQsX4fv2gIhW3H8hVw24mKCpmNoyV-9LND3OAR9ld80KeMH3lip863p_wBorIy1BAag7bRfvWcxsPrbqbox87VMrUWCEsry5epWxKYl2qNCT1GMv8SYAJ5WR0QZR0Qjvw5MXfZjohmbvrxJ7mWlc7fcvWoIXuO_q_yFkhi7A-fOZWm9sy8UDIlq-zNEPkVUwfqfWc_HbNHgvrk9Z6zZSNzB-dWAOT6QYAc1KeEVOIbvQxKkLkGMArTpydj5iLxz0aERvglKRl215Bqh6_jZu95T5yKv7X4R127ylpWYW2YDlTR9bgRE7Faw $ ampUrl最终看起来像这样: https ://www-qponverzum-hu.cdn.ampproject.org/update-cache/c/s/www.qponverzum.hu/ajanlat/budapest-elozd-meg-a-hajhullast- mikrokameras-hajdiagnosztika-hajhagyma-ES-fejborvizsgalattal-tanacsadas-5000-FT-helyett-2500-FT-ERT-biohajklinika-szepsegapolas-egeszseg /安培?amp_action =平齐&amp_ts = 1500362660&amp_url_signature = NjTCnmqUGpMY_CokGxchoczSOxnTLQvcQsX4fv2gIhW3H8hVw24mKCpmNoyV-9LND3OAR9ld80KeMH3lip863p_wBorIy1BAag7bRfvWcxsPrbqbox87VMrUWCEsry5epWxKYl2qNCT1GMv8SYAJ5WR0QZR0Qjvw5MXfZjohmbvrxJ7mWlc7fcvWoIXuO_q_yFkhi7A-fOZWm9sy8UDIlq-zNEPkVUwfqfWc_HbNHgvrk9Z6zZSNzB-dWAOT6QYAc1KeEVOIbvQxKkLkGMArTpydj5iLxz0aERvglKRl215Bqh6_jZu95T5yKv7X4R127ylpWYW2YDlTR9bgRE7Faw

If I make a simple GET request to this url(with a browser or curl) i get a 403 error('Your client does not have permission to get URL'). 如果我对此网址(使用浏览器或curl)发出简单的GET请求,则会收到403错误(“您的客户端无权获取网址”)。

I've checked the webserver logs, but it doesn't seem like there're any requests made to the public keys url. 我已经检查了网络服务器日志,但似乎没有对公钥网址发出任何请求。

I think I'm missing something very obvious, so any feedback would be greatly appreciated. 我想我错过了很明显的东西,所以任何反馈都会非常感激。

There's an error in $signatureUrl - it should be amp_ts instead of _ts in the query params and in openssl_sign add the fourth parameter openssl_sign($signatureUrl, $signature, $pkeyid, OPENSSL_ALGO_SHA256); $signatureUrl有一个错误 - 在查询参数中应该是amp_ts而不是_ts ,在openssl_sign添加第四个参数openssl_sign($signatureUrl, $signature, $pkeyid, OPENSSL_ALGO_SHA256);

The signature needs to be signed with SHA256 , if you omit the last parameter it uses SHA1 签名需要使用SHA256签名,如果省略它使用SHA1的最后一个参数

I've used your script with these 2 changes for my work project and it's working fine. 我已经使用你的脚本将这2个更改用于我的工作项目,并且它工作正常。

It should return "OK" in the response body if it's fine. 如果没问题,它应该在响应正文中返回“OK”。

Check this https://gist.github.com/krzysztofbukowski/739ccf4061d69360b5b2c8306f5878bd 检查这个https://gist.github.com/krzysztofbukowski/739ccf4061d69360b5b2c8306f5878bd

Try to set the response content type to "text/plain" for https://www.qponverzum.hu/.well-known/amphtml/apikey.pub as recommended in here 为“text / plain的”为尝试设置响应内容类型https://www.qponverzum.hu/.well-known/amphtml/apikey.pub建议在这里

========= =========

I use the script for update cache, but I got the 403 forbidden error. 我使用脚本进行更新缓存,但是我收到403禁止错误。 It's hard to debug and find out the root cause. 很难调试并找出根本原因。 Did someone succed? 有人成功了吗?

All the other answers have really helped - thanks. 所有其他答案都真的有帮助 - 谢谢。 I'm adding a little here which may hopefully also help. 我在这里补充一点,希望也有所帮助。

As @kul3r4 points out (I missed it first time round) the apikey.pub file needs to be served as plain text. 正如@ kul3r4指出的那样(我第一次错过了它),apikey.pub文件需要作为纯文本提供。 Here is the Nginx config rule for that; 这是Nginx配置规则;

    location /.well-known/amphtml/apikey.pub { ## serve amp public key as plain/text
         default_type text/plain;
    }

If you are echoing out @Krzysztof Bukowski's answer to the screen, the fact that &amp is in the url parameters means my browser was stripping out the amp part of the amp_ts and amp_url_signature so be aware of that. 如果你正在回应@Krzysztof Bukowski对屏幕的回答,那么&amp在url参数中的事实意味着我的浏览器正在剥离amp_tsamp_url_signatureamp部分,所以要注意这一点。

If you are struggling with the file paths and syntax of this; 如果你正在努力解决这个问题的文件路径和语法;

    $pkeyid = openssl_pkey_get_private("file://amp-private-key.pem");

Then just follow this answer here and put the contents of your private key in a variable -> Openssl and PHP 然后在这里按照这个答案,将私钥的内容放在一个变量 - > Openssl和PHP中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM