Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【20190724】Prerender nginx 配置 #98

Open
zhongxia245 opened this issue Jul 24, 2019 · 0 comments
Open

【20190724】Prerender nginx 配置 #98

zhongxia245 opened this issue Jul 24, 2019 · 0 comments
Labels

Comments

@zhongxia245
Copy link
Owner

zhongxia245 commented Jul 24, 2019

适用 eggjs + puppeteer 实现了一个抓取 CSR 页面的内容。

完成了服务,应该在 nginx 配置代理,把爬虫代理到SEO 服务来, 下面便是接口重写的 nginx 配置

location / {
    root   /usr/local/etc/nginx/html;
    index  index.html index.htm;

    set $prerender 0;
    if ($http_user_agent ~* "googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator") {
        set $prerender 1;
    }
    if ($args ~ "_escaped_fragment_") {
        set $prerender 1;
    }
    if ($http_user_agent ~ "Prerender") {
        set $prerender 0;
    }
    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)") {
        set $prerender 0;
    }

    if ($prerender = 1) {
       # rewrite ^/(.*) http://www.aaaa.com/html?url=$1;
        rewrite ^/(.*) http://your_domain.com/your_path?url=$1;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant