【问题标题】:Prerender + AngularJS - Crawlers time outPrerender + AngularJS - 爬虫超时
【发布时间】:2017-05-13 13:59:28
【问题描述】:

设置信息:

我已经在自己的服务器 Ubuntu 16 上成功安装了预渲染 (https://github.com/prerender/prerender)。

这是我的 .htaccess,它会在检测到爬虫时将 url 重写为 prerender。示例:http://www.example.nl/63/Merry 变为 http://example.nl:3000/http://www.example.nl/63/Merry

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|redditbot|slackbot|msnbot|googlebot|duckduckbot|bingbot|rogerbot|linkedinbot|embedly|flipboard|tumblr|bitlybot|SkypeUriPreview|nuzzel|Discordbot|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
RewriteRule ^(.*)$  http://example.nl:3000/http://www.example.nl/$1? [R=301,L]
#RewriteRule ^(.*)$  http://art.example.net/$1? [R=301,L] 

RewriteRule ^(.*)/(.*)$ /#$1/$2 [NC,L]

问题:

使用预渲染时,元数据未在 Skype、Reddit、Twitter 上加载。重写旧 PHP 网站的 url:http://art.example.net(目前在 htaccess 中注释)确实有效。因为 PHP 和 Angular 网站上的所有元标记都是相同的,所以 prerenderer 很可能是问题的原因。

来自 Twitter 的错误示例(https://cards-dev.twitter.com/validator 使用 url:http://example.nl/63/Merry)使用 Prerender:

ERROR: Failed to fetch page due to: HttpConnectionTimeout
WARN:  this card is redirected to http://example.nl:3000/http://www.example.nl/63/Merry

重定向到 art.example.net 时的 Twitter(也使用主 URL:http://example.nl/63/Merry

INFO:  Page fetched successfully
INFO:  19 metatags were found
INFO:  twitter:card = summary_large_image tag found
INFO:  Card loaded successfully
WARN:  this card is redirected to http://art.example.net/63/Merry

使用 PHP 版本可以正常工作,并且正在加载所有元数据。

将来我想完全删除 PHP 网站,所以我真的很希望它与 Prerender 一起工作。 Prerender 确实在 Discord 和 Postman 中工作(修改了 User Agent 标头)。我只是不知道为什么它不适用于其他一些代理。

【问题讨论】:

    标签: javascript angularjs prerender


    【解决方案1】:

    您的重写规则应该是代理,而不是重定向。重定向到您的预渲染服务器会导致各种问题,包括告诉 Google 将用户从搜索结果直接发送到您的预渲染服务器(这真的很糟糕!)。

    重写规则部分应该是:

    RewriteRule ^(.*)$  http://example.nl:3000/http://www.example.nl/$1? [P,L]
    

    【讨论】:

      【解决方案2】:

      解决办法:

      Twitter 和其他爬虫无法处理网址中的点和“:”。因此,不允许使用纯 IP 地址和端口号。

      要解决此问题,您可以创建一个重定向到 Node.js 应用程序的子域

      我的子域 Apache 虚拟主机:

      <VirtualHost *:80>
          ServerAdmin info@example.net
          ServerName prerender.example.net
          ServerAlias prerender.example.net  
          ProxyPass / http://localhost:3000/ connectiontimeout=5 timeout=30   
      </VirtualHost>
      

      https://serverfault.com/questions/497856/using-an-apache-virtualhost-to-access-a-node-js-instance-on-the-same-server

      连同 prerender.io 自己的答案,我设法让它工作。

      虽然代理和重定向对社交媒体爬虫来说并不重要,因为 URL 已经粘贴在那里。使用 Proxy 标签是个好习惯。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-07
        • 1970-01-01
        • 2013-02-03
        • 2019-06-24
        • 2012-08-08
        • 1970-01-01
        相关资源
        最近更新 更多