AngularJS не работает со сторонним сервисом предварительной визуализации - PullRequest
0 голосов
/ 14 апреля 2019

Я использую AngularJS с SEO4Ajax. Я запускаю свой веб-сайт в Docker-контейнере с помощью nginx. Я скопировал все конфигурации nginx из SEO4Ajax в Docker-контейнер. Seo4Ajax создал моментальные снимки, но URL, оканчивающийся на ?_escaped_fragment_=, не работает.

Заголовок AngularJS

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

AngularJS Config

$locationProvider.html5Mode(true).hashPrefix('!');

Nginx Config

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 не производит. Должен отображаться заголовок seo4ajax на основе this .

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 forward на IP-адрес своего цифрового цифрового сервера.

Ожидаемый результат:

curl -H "Пользователь-агент: бот" -I https://www.mywebsite.net

должно выдать X-Powered-By: SEO4Ajax в заголовке

1 Ответ

1 голос
/ 08 мая 2019

_escaped_fragment_ устарела с середины 2018 года. Вы можете попытаться избежать его использования. prerender.io может быть выбором для вас.

Ссылка:

  1. https://developers.google.com/search/docs/ajax-crawling/docs/specification
  2. https://medium.com/finnovate-io/googlebot-no-longer-picking-up-content-in-prerender-io-pages-ae21d9710459
...