【问题标题】:Varnish configuration with phpMyAdmin and VirtulHosts使用 phpMyAdmin 和 VirtulHosts 进行清漆配置
【发布时间】:2013-11-28 23:35:30
【问题描述】:

我在配置 default.vcl 时遇到问题:varnish 正在阻止登录到 phpMyAdmin,并且在身份验证后总是显示登录页面。

Web 服务器只能托管 WordPress 站点和 phpMyAdmin,每个用户都可以在其中管理他的数据库。

http://phpMyAdmin.domain.com //for phpMyAdmin where users access their database
http://www.site1.com  
http://www.site2.com  
http://www.site3.com //and so on  

我在哪里出错或遗漏了什么?

这是我的实际 default.vcl

backend default {
    .host = "127.0.0.1";
    .port = "8000";
}

acl purge {
    # Web server with plugin which will issue PURGE requests
    "127.0.0.1";
    "localhost";
}

sub vcl_recv {
    if (req.request == "PURGE") {
        if (!client.ip ~ purge) {
            error 405 "Not allowed.";
        }
        ban("req.url ~ ^" + req.url + "$ && req.http.host == " + req.http.host);
    }

    # Normalize content-encoding
    if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|lzma|tbz)(\?.*|)$") {
            remove req.http.Accept-Encoding;
        } elsif (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            remove req.http.Accept-Encoding;
        }
    }

    # Remove cookies and query string for real static files
    if (req.url ~ "^/[^?]+\.(gif|jpg|jpeg|swf|css|js|txt|flv|mp3|mp4|pdf|ico|png|gz|zip|lzma|bz2|tgz|tbz)(\?.*|)$") {
       unset req.http.cookie;
       set req.url = regsub(req.url, "\?.*$", "");
    }

    # Don't cache backend
    if (req.url ~ "wp-(login|admin|comments-post.php|cron.php)") {
        return (pass);
    }

    if (req.url ~ "pmacloud") {
        return(pass);
    }

    return (lookup);
}

sub vcl_fetch {
  # Don't store backend
  if (req.url ~ "wp-(login|admin|comments-post.php|cron.php)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") {
    return (hit_for_pass);
  }
  if ( (!(req.url ~ "(wp-(login|admin|comments-post.php|cron.php)|login)")) || (req.request == "GET") ) {
    unset beresp.http.set-cookie;
    set beresp.ttl = 4h;
  }
  if (req.url ~ "\.(gif|jpg|jpeg|swf|css|js|txt|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
     set beresp.ttl = 30d;
  } #else {
  # set beresp.do_esi = true;
  #}
}
sub vcl_hit {
        if (req.request == "PURGE") {
                purge;
                error 200 "Purged.";
        }
}

sub vcl_miss {
        if (req.request == "PURGE") {
                purge;
                error 200 "Purged.";
        }
}

【问题讨论】:

    标签: wordpress phpmyadmin varnish varnish-vcl


    【解决方案1】:

    启用访问phpMyAdmin的解决方案是添加

    sub vcl_recv

    if (req.http.Host == "phpMyAdmin.domain.com") {
       return (pass);
    }
    

    sub vcl_fetch

    if (req.http.Host == "phpMyAdmin.domain.com") {
        return (hit_for_pass);
    }
    

    【讨论】:

      【解决方案2】:

      在您的 vcl_fetch 中,您将删除 set-cookie 标头用于除 WordPress 特定 URL 之外的所有其他内容。

      具体来说:

      # Don't store backend
      if (req.url ~ "wp-(login|admin|comments-post.php|cron.php)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") {
        return (hit_for_pass);
      }
      if ( (!(req.url ~ "(wp-(login|admin|comments-post.php|cron.php)|login)")) || (req.request == "GET") ) {
        unset beresp.http.set-cookie;
        set beresp.ttl = 4h;
      }
      

      您需要调整这两行以查找 phpMyAdmin 特定的 URL 或域。

      例如,如果 phpMyAdmin 始终托管在 phpmyadmin.domain.com 上,您可以执行以下操作:

      # Don't store backend
      if ( 
        req.http.host ~ "phpmyadmin"
        || req.url ~ "wp-(login|admin|comments-post.php|cron.php)"
        || req.url ~ "preview=true"
        || req.url ~ "xmlrpc.php"
      ) {
        return (hit_for_pass);
      }
      if (
        req.http.host ~ "phpmyadmin"
        || (!(req.url ~ "(wp-(login|admin|comments-post.php|cron.php)|login)"))
        || (req.request == "GET")
      ) {
        unset beresp.http.set-cookie;
        set beresp.ttl = 4h;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-09-21
        • 1970-01-01
        • 2016-01-13
        • 2016-05-06
        • 2019-08-26
        • 2013-06-22
        • 1970-01-01
        相关资源
        最近更新 更多