php - Nginx:如何将Googlebot流量转移到Varnish

标签 php nginx varnish

在 Nginx 中,如何将 Googlebot 流量代理到 Varnish 后端,同时将所有其他流量定向到我的 PHP 后端?

我想要这样的东西:

try_files $uri $uri/ /index.php;
if ($http_user_agent ~* Googlebot) {
    proxy_pass http://varnish;
}
location ~* \.php$ {
    fastcgi_pass 127.0.0.1:9000;
}

但是,上述内容在 server 上下文中不起作用,因为 proxy_passserver 上下文中是不允许的。

如果我将上述内容包装在 location / {} 块中,那么我在 if 块中有一个 location ,它使 if evil 。 (我试过了,它有时奏效,但它是间歇性的,不可预测的。)

有什么办法可以使这项工作?

最佳答案

您可以使用错误页面在内部将流量路由到服务器块中的其他位置,然后使用该位置块代理 Varnish 。

例子:

server {
    error_page 519 = @google;
    if ($http_user_agent ~* Googlebot) {
        return 519;
}
    location @google {
         proxy_pass http://varnish;
}

关于php - Nginx:如何将Googlebot流量转移到Varnish,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19433360/

相关文章:

php - 使用安全登录抓取网站内容

php - 交响乐 2 错误 : Call to a member function get() on a non-object

Magento 缓存 - 关于 Varnish、Redis、APC、Memcache 的困惑

ubuntu - Varnish 似乎在工作,但 max-age=0

magento - Varnish 缓存清空 Magento 中的购物车

php - 与 Doctrine PHP 的关联

python - Gunicorn-Django : django project not found

ruby-on-rails -/usr/bin/env : passenger: No such file or directory and with exit status 1 (failed)

laravel - link_to 从容器中托管的站点中剥离端口

php - 如果当前日期和时间大于 Mysql 中存储的日期和时间,则回显一些文本