AngularJS不适用于第三方预渲染服务

时间:2019-04-14 07:15:28

标签: angularjs nginx seo prerender

我正在将AngularJS与SEO4Ajax一起使用。我使用nginx在Docker容器中运行我的网站。我将所有nginx配置从SEO4Ajax复制到docker容器。 Seo4Ajax已经创建了快照,但是以?_escaped_fragment_=结尾的网址不起作用。

AngularJS标头

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

AngularJS配置

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

Nginx配置

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“用户代理:机器人” -I https://www.mywebsite.net

应在标题中生成 X-Powered-By:SEO4Ajax

1 个答案:

答案 0 :(得分:1)