我用的是Angularjs和seo4ajax。我用nginx在docker容器中运行我的网站。我将所有nginx配置从seo4ajax复制到docker容器。seo4ajax已经创建了快照,但是以?_escaped_fragment_=结尾的url不起作用。
Angularjs标题

meta(name='fragment', content='!')

Angularjs配置
$locationProvider.html5Mode(true).hashPrefix('!');

NGNX配置
server {
    listen 80;
    sendfile off;
    expires 0;
    location / {
        root /usr/share/nginx/html;
        index index.html index.htm;
        try_files $uri @s4a_analyse $uri/ /index.html =404;

        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, OPTIONS';
    }

    ### This location determines if a request comes from bots
    location @s4a_analyse {

        ### If the request comes from a bot, proxy the request through /s4a_proxy location
        if ($http_user_agent ~* (google|bot|spider|pinterest|crawler|archiver|flipboardproxy|mediapartners|facebookexternalhit|insights|quora|whatsapp|slurp)) {
            rewrite ^(.*)$ /s4a_proxy last;
        }

        ### Uncomment the 3 following lines to support the _escaped_fragment_= parameter
        if ($args ~ "_escaped_fragment_=") {
            rewrite  ^(.*)$  /s4a_proxy  last;
        }

        if ($http_from ~* .+) {
            rewrite ^(.*)$ /s4a_proxy last;
        }

        ### Otherwise serve /index.html
        rewrite ^(.*)$ /index.html last;
    }

    ### This location proxy requests coming from bots to SEO4Ajax
    ### You can update the resolver directive with your own DNS provider if needed
    location /s4a_proxy {
        set $s4a_domain 'https://api.seo4ajax.com/SEO4AJAX_TOKEN';
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        resolver 8.8.8.8 8.8.4.4;
        proxy_pass $s4a_domain$request_uri;
    }
}

页眉
我试图卷曲url来检索头,X-Powered-By: SEO4Ajax不产生。它应该显示基于this的seo4ajax头。
curl -H "User-Agent: Bot" -I http://www.mywebsite.net

HTTP/1.1 200 OK
Date: Sun, 14 Apr 2019 07:08:56 GMT
Content-Type: text/html
Connection: keep-alive
Set-Cookie: __cfduid=d464769ca8ded696b9c1dcfd4ed5bc14c1555225736; expires=Mon, 13-Apr-20 07:08:56 GMT; path=/; domain=.mywebsite.net; HttpOnly
Accept-Ranges: bytes
Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS
Access-Control-Allow-Origin: *
Cache-Control: max-age=0
Expires: Sun, 14 Apr 2019 07:08:56 GMT
Last-Modified: Sun, 14 Apr 2019 05:00:06 GMT
Strict-Transport-Security: max-age=315360000; includeSubdomains; preload
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Xss-Protection: 1; mode=block
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 4c73d9f24871a542-NRT

对于服务器,我使用cloudflare转发到我的数字海洋服务器droplet ip。
预期产量:
curl-h“用户代理:bot”-ihttps://www.mywebsite.net
应该在header中生成x-powered-by:seo4ajax

最佳答案

_逃逸碎片自2018年年中以来一直被弃用。你可以尽量避免使用它。prerender.io可能是你的选择。
参考文献:
https://developers.google.com/search/docs/ajax-crawling/docs/specification
https://medium.com/finnovate-io/googlebot-no-longer-picking-up-content-in-prerender-io-pages-ae21d9710459

10-04 14:14