ini 为nginx改变了prerender.io nginx.conf

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ini 为nginx改变了prerender.io nginx.conf相关的知识,希望对你有一定的参考价值。

# Change YOUR_TOKEN to your prerender token and uncomment that line if you want to cache urls and view crawl stats
# Change example.com (server_name) to your website url
# Change /path/to/your/root to the correct value

# Generate $prerender_ua bool value based on user agent
# indexation bots will get this as 1, 
# prerender user agent will always get 0 (avoid loops)
map $http_user_agent $prerender_ua {

    default 0;

    "~Prerender" 0;

    "~*baiduspider" 1;
    "~*twitterbot" 1;
    "~*baiduspider" 1;
    "~*facebookexternalhit" 1;
    "~*rogerbot" 1;
    "~*linkedinbot" 1;
    "~*embedly" 1;
    "~*quora link preview" 1;
    "~*showyoubot" 1;
    "~*outbrain" 1;
    "~*pinterest" 1;
    "~*slackbot" 1;
    "~*vkShare" 1;
    "~*Slack-ImgProxy" 1;
    "~*Slackbot-LinkExpanding" 1;
    "~*Site Analyzer" 1;
    "~*SiteAnalyzerBot" 1;
    "~*Viber" 1;
    "~*Whatsapp" 1;
    "~*Telegram" 1;
    "~*W3C_Validator" 1;
}

# Generate $prerender bool value based on _escaped_fragement_ argument presence
# detection OR get the $prerender_ua bool value
map $args $prerender {
    default $prerender_ua;
    "~(^|&)_escaped_fragment_=" 1;
}

server {
    listen 80;
    server_name example.com;
 
    root   /path/to/your/root;
    index  index.html;
    
    # 5xx errors managed by your app
    proxy_intercept_errors on;  
    error_page 500 502 503 504 =200 /index.html;
    # uncomment if you want 404 managed by the app
    # error_page 404 =200 /index.html;

    
    location / {
        try_files $uri @prerender;
    }
 
    location @prerender {
        #proxy_set_header X-Prerender-Token YOUR_TOKEN;
        
        # static files extensions detection. These should be managed by the
        # $uri part of the try_file "try_files $uri @prerender;". If we get
        # there it means either the static file is missing OR we need to
        # handle it in the app. In that second case see error_page instructions       
        if ($uri ~* "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)") {
            return 404;
        }
        
        #resolve using Google's DNS server to force DNS resolution and prevent caching of IPs
        resolver 8.8.8.8;
 
        if ($prerender = 1) {
            #setting proxyprerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
            #     local prerender
            #set $proxyprerender "127.0.0.1:3000";
            #     Or online service
            set $proxyprerender "service.prerender.io";
        
            proxy_intercept_errors on;
            # $http_x_forwarded_proto could be used instead of $scheme
            # if you are behind an ssl terminator with X-Forwarded-Proto set    
            rewrite .* /$scheme://$host$request_uri? break;
            proxy_pass http://$proxyprerender;
        }
        if ($prerender = 0) {
            rewrite .* /index.html break;
        }
    }
}

以上是关于ini 为nginx改变了prerender.io nginx.conf的主要内容,如果未能解决你的问题,请参考以下文章

prerender.io 搜索引擎优化 部署成windows服务 实现开机自动开启服务

Single Page App + Amazon S3 + Amazon CloudFront + Prerender.io - 如何设置?

javascript 从控制台清除prerender.io中的所有缓存页面

apache_conf Apache的官方prerender.io .htaccess。

apache_conf Apache的官方prerender.io .htaccess。

javascript NodeJs ExpressJS中间件,允许特定于bot / crawler的路由。基于OS项目的Prerender.IO中间件用于节点。