这是我在开发环境中尝试过的,我还不确定我们是否会在生产中使用它。
清漆配置
probe checkslash {
.url = "/robots.txt";
.interval = 500s;
.timeout = 10s;
}
include "backends.vcl";
/** generic config from here down */
sub vcl_recv{
/* if the drupals are down, this is how long we cache for */
set req.grace = 6h;
/* Make sure we direct 443 traffic to the secure drupal */
if (server.port == 443 ) {
set req.backend = drpau_ssl_director;
} else {
/* port 80 traffic goes to the correct LB */
set req.backend = drpau_director;
}
# just pass through non-page files, and the login page
if (req.url ~ "(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js|htc|ejs)(\?.*)?$") {
} else if (req.url ~ "(?i)(sites/default/files)|(js/)|(/login)" ) {
} else if (req.esi_level == 0 ) {
# pass regular pages to a spoecial url
set req.url = "/esi" + req.url;
}
return (lookup);
}
sub vcl_fetch {
if (req.url ~ "/esi/" && req.esi_level == 0 ) {
set beresp.do_esi = true; /* Do ESI processing */
}
}
然后在 apache 中,我重定向所有通过 esi 前缀的页面请求
RewriteRule ^esi/(.*)$ test.php [L]
和测试 php 是
<?php
define('DRUPAL_ROOT', getcwd());
// We prepare only a minimal bootstrap.
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
global $user;
$roles = user_roles();
if (in_array('anonymous user', $user->roles)) {
$uri = preg_replace('#^/esi#', '', $_SERVER[REQUEST_URI]);
echo "<esi:include src=\"http://$_SERVER[SERVER_NAME]$uri\"/>";
} else {
header("Location: https://$_SERVER[SERVER_NAME]/login");
}