将Crawler重定向到内部服务

时间:2015-03-12 03:44:23

标签: facebook nginx service web-crawler

我想设置nginx让某些抓取工具从端口9998上运行的内部服务获取数据。

因此,例如,当浏览器请求www.mywebsite.com/resource/1时,它将查看根文件夹,但当爬虫(例如FB爬虫)请求相同的资源时,它应该返回页面由服务于127.0.0.1:9998/resource/1。

这是我提出的配置但不按预期工作。正确识别用户代理,但不从服务获取数据。

    location / {
        if ($http_user_agent ~ Facebot) {
            proxy_pass http://127.0.0.1:9998;
        }

        root /etc/www/website;
        try_files $uri /index.html;
        ... other stuff...
   }

1 个答案:

答案 0 :(得分:0)

break之后添加proxy_pass

location / {
    if ($http_user_agent ~ Facebot) {
        proxy_pass http://127.0.0.1:9998;
        break;
    }

    root /etc/www/website;
    try_files $uri /index.html;
    ... other stuff...
}