Magento varnish缓存服务器:错误503服务不可用

Magento varnish缓存服务器:错误503服务不可用,magento,amazon-ec2,varnish,Magento,Amazon Ec2,Varnish,我在一个AWS EC2实例上安装了varnish(varnish-3.0.5修订版1a89b1f)和NexAccess松节油(0.6.1),并将varnish listen更改为80,httpd listen 8080 前端错误: Error 503 Service Unavailable Service Unavailable Guru Meditation: XID: 2017409829 Varnish cache server 8080可以访问后端magento “netstat-nt

我在一个AWS EC2实例上安装了varnish(varnish-3.0.5修订版1a89b1f)和NexAccess松节油(0.6.1),并将varnish listen更改为80,httpd listen 8080

前端错误:

Error 503 Service Unavailable
Service Unavailable
Guru Meditation:
XID: 2017409829
Varnish cache server
8080可以访问后端magento

“netstat-ntl”输出为:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:6082              0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN
tcp        0      0 :::80                       :::*                        LISTEN
tcp        0      0 :::8080                     :::*                        LISTEN
tcp        0      0 :::6379                     :::*                        LISTEN
我尝试通过以下技巧来修复它:

  • 调整第一个字节\u超时和两个字节之间的\u超时
  • “chkconfig--list varnish”以确保varnish状态处于打开状态
  • “服务iptables状态”已关闭
  • 设置一个更大的连接超时
但没有任何帮助

我用varnishlog来查找

FetchError   - http first read error: -1 11 (Resource temporarily unavailable)
以下是由松节油创建的default.vcl

C{
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>
static pthread_mutex_t lrand_mutex = PTHREAD_MUTEX_INITIALIZER;
void generate_uuid(char* buf) {
pthread_mutex_lock(&lrand_mutex);
long a = lrand48();
long b = lrand48();
long c = lrand48();
long d = lrand48();
pthread_mutex_unlock(&lrand_mutex);
sprintf(buf, "frontend=%08lx%04lx%04lx%04lx%04lx%08lx",
a,
b & 0xffff,
(b & ((long)0x0fff0000) >> 16) | 0x4000,
(c & 0x0fff) | 0x8000,
(c & (long)0xffff0000) >> 16,
d
);
return;
}
}C
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 100s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 1200s;
}
backend admin {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 600s;
.between_bytes_timeout = 1200s;
}
acl crawler_acl {
"127.0.0.1";
}
acl debug_acl {
}
sub generate_session {
if (req.url ~ ".*[&?]SID=([^&]+).*") {
set req.http.X-Varnish-Faked-Session = regsub(
req.url, ".*[&?]SID=([^&]+).*", "frontend=\1");
} else {
C{
char uuid_buf [50];
generate_uuid(uuid_buf);
VRT_SetHdr(sp, HDR_REQ,
"\030X-Varnish-Faked-Session:",
uuid_buf,
vrt_magic_string_end
);
}C
}
if (req.http.Cookie) {
std.collect(req.http.Cookie);
set req.http.Cookie = req.http.X-Varnish-Faked-Session +
"; " + req.http.Cookie;
} else {
set req.http.Cookie = req.http.X-Varnish-Faked-Session;
}
}
sub generate_session_expires {
C{
time_t now = time(NULL);
struct tm now_tm = *gmtime(&now);
now_tm.tm_sec += 3600;
mktime(&now_tm);
char date_buf [50];
strftime(date_buf, sizeof(date_buf)-1, "%a, %d-%b-%Y %H:%M:%S %Z", &now_tm);
VRT_SetHdr(sp, HDR_RESP,
"\031X-Varnish-Cookie-Expires:",
date_buf,
vrt_magic_string_end
);
}C
}
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (!true || req.http.Authorization ||
req.request !~ "^(GET|HEAD)$" ||
req.http.Cookie ~ "varnish_bypass=1") {
return (pipe);
}
set req.url = regsuball(req.url, "(.*)//+(.*)", "\1/\2");
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
}
}
if (req.url ~ "^(/magento2/media/|/magento2/skin/|/magento2/js/|/magento2/)(?:(?:index|litespeed)\.php/)?") {
set req.http.X-Turpentine-Secret-Handshake = "1";
if (req.url ~ "^(/magento2/media/|/magento2/skin/|/magento2/js/|/magento2/)(?:(?:index|litespeed)\.php/)?admin") {
set req.backend = admin;
return (pipe);
}
if (req.http.Cookie ~ "\bcurrency=") {
set req.http.X-Varnish-Currency = regsub(
req.http.Cookie, ".*\bcurrency=([^;]*).*", "\1");
}
if (req.http.Cookie ~ "\bstore=") {
set req.http.X-Varnish-Store = regsub(
req.http.Cookie, ".*\bstore=([^;]*).*", "\1");
}
if (req.url ~ "/turpentine/esi/get(?:Block|FormKey)/") {
set req.http.X-Varnish-Esi-Method = regsub(
req.url, ".*/method/(\w+)/.*", "\1");
set req.http.X-Varnish-Esi-Access = regsub(
req.url, ".*/access/(\w+)/.*", "\1");
if (req.http.X-Varnish-Esi-Method == "esi" && req.esi_level == 0 &&
!(true || client.ip ~ debug_acl)) {
error 403 "External ESI requests are not allowed";
}
}
if (req.http.Cookie !~ "frontend=") {
if (client.ip ~ crawler_acl ||
req.http.User-Agent ~ "^(?:ApacheBench/.*|.*Googlebot.*|JoeDog/.*Siege.*|magespeedtest\.com|Nexcessnet_Turpentine/.*)$") {
set req.http.Cookie = "frontend=crawler-session";
} else {
call generate_session;
}
}
if (true &&
req.url ~ ".*\.(?:css|js|jpe?g|png|gif|ico|swf)(?=\?|&|$)") {
unset req.http.Cookie;
unset req.http.X-Varnish-Faked-Session;
return (lookup);
}
if (req.url ~ "^(/magento2/media/|/magento2/skin/|/magento2/js/|/magento2/)(?:(?:index|litespeed)\.php/)?(?:admin|api|cron\.php|\admin|/admin)" ||
req.url ~ "\?.*__from_store=") {
return (pipe);
}
if (true &&
req.url ~ "(?:[?&](?:__SID|XDEBUG_PROFILE)(?=[&=]|$))") {
return (pass);
}
if (req.url ~ "[?&](utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=") {
set req.url = regsuball(req.url, "(?:(\?)?|&)(?:utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=[^&]+", "\1");
set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1");
}
return (lookup);
}
}
sub vcl_pipe {
unset bereq.http.X-Turpentine-Secret-Handshake;
set bereq.http.Connection = "close";
}
sub vcl_hash {
hash_data(req.url);
if (req.http.Host) {
hash_data(req.http.Host);
} else {
hash_data(server.ip);
}
hash_data(req.http.Ssl-Offloaded);
if (req.http.X-Normalized-User-Agent) {
hash_data(req.http.X-Normalized-User-Agent);
}
if (req.http.Accept-Encoding) {
hash_data(req.http.Accept-Encoding);
}
if (req.http.X-Varnish-Store || req.http.X-Varnish-Currency) {
hash_data("s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency);
}
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1"));
}
return (hash);
}
sub vcl_hit {
}
sub vcl_fetch {
set req.grace = 15s;
set beresp.http.X-Varnish-Host = req.http.host;
set beresp.http.X-Varnish-URL = req.url;
if (req.url ~ "^(/magento2/media/|/magento2/skin/|/magento2/js/|/magento2/)(?:(?:index|litespeed)\.php/)?") {
unset beresp.http.Vary;
set beresp.do_gzip = true;
if (beresp.status != 200 && beresp.status != 404) {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (beresp.http.Set-Cookie) {
set beresp.http.X-Varnish-Set-Cookie = beresp.http.Set-Cookie;
unset beresp.http.Set-Cookie;
}
unset beresp.http.Cache-Control;
unset beresp.http.Expires;
unset beresp.http.Pragma;
unset beresp.http.Cache;
unset beresp.http.Age;
if (beresp.http.X-Turpentine-Esi == "1") {
set beresp.do_esi = true;
}
if (beresp.http.X-Turpentine-Cache == "0") {
set beresp.ttl = 15s;
return (hit_for_pass);
} else {
if (true &&
bereq.url ~ ".*\.(?:css|js|jpe?g|png|gif|ico|swf)(?=\?|&|$)") {
set beresp.ttl = 28800s;
set beresp.http.Cache-Control = "max-age=28800";
} elseif (req.http.X-Varnish-Esi-Method) {
if (req.http.X-Varnish-Esi-Access == "private" &&
req.http.Cookie ~ "frontend=") {
set beresp.http.X-Varnish-Session = regsub(req.http.Cookie,
"^.*?frontend=([^;]*);*.*$", "\1");
}
if (req.http.X-Varnish-Esi-Method == "ajax" &&
req.http.X-Varnish-Esi-Access == "public") {
set beresp.http.Cache-Control = "max-age=" + regsub(
req.url, ".*/ttl/(\d+)/.*", "\1");
}
set beresp.ttl = std.duration(
regsub(
req.url, ".*/ttl/(\d+)/.*", "\1s"),
300s);
if (beresp.ttl == 0s) {
set beresp.ttl = 15s;
return (hit_for_pass);
}
} else {
set beresp.ttl = 600s;
}
}
}
return (deliver);
}
}
sub vcl_deliver {
if (req.http.X-Varnish-Faked-Session) {
call generate_session_expires;
set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
"; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/";
if (req.http.Host) {
set resp.http.Set-Cookie = resp.http.Set-Cookie +
"; domain=" + regsub(req.http.Host, ":\d+$", "");
}
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly";
unset resp.http.X-Varnish-Cookie-Expires;
}
if (req.http.X-Varnish-Esi-Method == "ajax" && req.http.X-Varnish-Esi-Access == "private") {
set resp.http.Cache-Control = "no-cache";
}
if (true || client.ip ~ debug_acl) {
set resp.http.X-Varnish-Hits = obj.hits;
set resp.http.X-Varnish-Esi-Method = req.http.X-Varnish-Esi-Method;
set resp.http.X-Varnish-Esi-Access = req.http.X-Varnish-Esi-Access;
set resp.http.X-Varnish-Currency = req.http.X-Varnish-Currency;
set resp.http.X-Varnish-Store = req.http.X-Varnish-Store;
} else {
unset resp.http.X-Varnish;
unset resp.http.Via;
unset resp.http.X-Powered-By;
unset resp.http.Server;
unset resp.http.X-Turpentine-Cache;
unset resp.http.X-Turpentine-Esi;
unset resp.http.X-Turpentine-Flush-Events;
unset resp.http.X-Turpentine-Block;
unset resp.http.X-Varnish-Session;
unset resp.http.X-Varnish-Host;
unset resp.http.X-Varnish-URL;
unset resp.http.X-Varnish-Set-Cookie;
}
}
C{
#包括
#包括
#包括
#包括
静态pthread\u mutex\u t lr和\u mutex=pthread\u mutex\u初始值设定项;
void生成_uuid(char*buf){
pthread_mutex_lock(&lr和_mutex);
长a=LR和48();
长b=lr和48();
长c=lR和48();
长d=lrand48();
pthread_mutex_unlock(&lr和_mutex);
sprintf(buf,“前端=%08lx%04lx%04lx%04lx%04lx%04lx%08lx”,
A.
b&0xffff,
(b&((长)0x0fff0000)>>16)| 0x4000,
(c&0x0fff)| 0x8000,
(c&(长)0xffff0000)>>16,
D
);
返回;
}
}C
进口性病;
后端默认值{
.host=“127.0.0.1”;
.port=“8080”;
.连接超时=100s;
.第一字节超时=600s;
.字节之间\u超时=1200s;
}
后端管理员{
.host=“127.0.0.1”;
.port=“8080”;
.第一字节超时=600s;
.字节之间\u超时=1200s;
}
acl爬虫程序{
"127.0.0.1";
}
acl调试\u acl{
}
子生成会话{
如果(req.url~”*[&?]SID=([^&]+)*){
设置req.http.X-Varnish-Faked-Session=regsub(
req.url,“.[&?]SID=([^&]+)*”,“前端=\1”);
}否则{
C{
char uuid_buf[50];
生成uuid(uuid\u buf);
VRT_设置HDR(sp、HDR_要求、,
“\030X清漆伪造会话:”,
uuid_buf,
vrt_魔术_字符串_结束
);
}C
}
if(req.http.Cookie){
std.collect(请求http.Cookie);
设置req.http.Cookie=req.http.X-Varnish-Faked-Session+
“;”+req.http.Cookie;
}否则{
设置req.http.Cookie=req.http.X-Varnish-Faked-Session;
}
}
子生成会话到期{
C{
time\u t now=时间(空);
struct tm now_tm=*gmtime(&now);
现在_tm.tm_sec+=3600;
mktime&now_tm;
char date_buf[50];
strftime(date\u buf,sizeof(date\u buf)-1、%a、%d-%b-%Y%H:%M:%S%Z、&now\u tm);
VRT_设置HDR(sp、HDR_分别,
“\031X清漆Cookie过期:”,
日期:,
vrt_魔术_字符串_结束
);
}C
}
子vcl_recv{
如果(请求重新启动==0){
如果(请求http.X-Forwarded-For){
设置req.http.X-Forwarded-For=
req.http.X-Forwarded-For+“,”+client.ip;
}否则{
设置req.http.X-Forwarded-For=client.ip;
}
}
如果(!true | | req.http.Authorization||
请求!~“^(获取|头)$”||
req.http.Cookie~“varnish\u bypass=1”){
回流管;
}
设置req.url=regsuball(req.url,(.*)/+(.*),“\1/\2”);
if(请求http接受编码){
if(req.http.Accept-Encoding~“gzip”){
设置req.http.Accept-Encoding=“gzip”;
}else if(req.http.Accept-Encoding~“deflate”){
设置req.http.Accept-Encoding=“deflate”;
}否则{
unset req.http.Accept-Encoding;
}
}
如果(req.url~“^(/magento2/media/|/magento2/skin/|/magento2/js/|/magento2/)(?:(?:index | litespeed)\.php/)){
设置req.http.X-Turpentine-Secret-Handshake=“1”;
如果(req.url~“^(/magento2/media/|/magento2/skin/|/magento2/js/|/magento2/)(?:(?:index | litespeed)\.php/)?admin”){
设置req.backend=admin;
回流管;
}
如果(req.http.Cookie~“\bcurrency=”){
设置req.http.X-Varnish-Currency=regsub(
req.http.Cookie,“.*\b货币=([^;]*)*)*”,“\1”);
}
如果(req.http.Cookie~“\bstore=”){
设置req.http.X-Varnish-Store=regsub(
req.http.Cookie,“.*\b存储=([^;]*).*”,“\1”);
}
if(req.url~“/turpentine/esi/get(?:Block | FormKey)/”){
设置req.http.X-Varnish-Esi-Method=regsub(
req.url,“.*/method/(\w+/*”,“\1”);
设置req.http.X-Varnish-Esi-Access=regsub(
req.url,“.*/access/(\w+/*”,“\1”);
如果(req.http.X-Varnish-Esi-Method==“Esi”&&req.Esi_level==0&&
!(true | | client.ip~debug_acl)){
错误403“不允许外部ESI请求”;
}
}
如果(req.http.Cookie!~“frontend=){
if(client.ip~crawler\u acl||
req.http.User-Agent~“^(?:ApacheBench/*.*Googlebot.*JoeDog/.*seake.*magespeedtest\.com | Nexcessnet_Turpentine/.*)$”){
set req.http.Cookie=“frontend=crawler session”;
}否则{
呼叫生成会话;
}
}
如果(真的&&
req.url~“*\”(?:css | js | jpe | g | png | gif | ico | swf)(?=\?|&$)){
unset req.http.Cookie;
unset req.http.X-Varnish-Faked-Session;
返回(查找);
}
如果(req.url)“^(/magento2/media/|/magento2/skin/|/magento2/js/|/magento2/)(?:(?:index | litespeed)\.php/)(?:admin | api | cron\.php | \ admin |/admin)”||
req.url~“\?*”来自\u store=“){
回流管;
}
如果(真的&&
req.url~“(?:[?&](?:uu SID | XDEBUG_uprofile)(?=[&=]|$)”){
返回(通行证);
}
如果(请求url~“[?&](utm|U来源| utm|U媒体| utm|U活动| gclid | cx | ie | cof |站点url)=”){
设置req.url=regsuball(req.url,(?:(\?)?|和)(?:utm|U源| utm|U中| utm|U活动| gclid | cx | ie | cof | siteurl)=[^&]+,“\1”);
设置req.url=regsuball(req.url,“(?:(\?)&“\?$”,“\1”);
}
返回(查找);
}
}
子vcl_管{
unset bereq.http.X-松节油-秘密握手;
设置bereq.http.Connection=“close”;
}
子vcl_散列{
散列数据(请求url);
if(req.http.Host){
散列数据(请求http.Host);
}否则{
散列数据(server.ip);
}
散列数据(请求http.Ssl卸载);
if(请求http.X-Normalized-User-Agent){
哈希_数据(请求http.X-Normalized-User-Agent);
}
if(请求http接受编码){
散列数据(请求http接受编码);
}
if(req.http.X-Varnish-Store | | req.http.X-Varnish-Currency){
哈希_数据(“s=“+req.http.X-Varnish-Store+”&c=“+req.http.X-Varnish-Currency”);
}
if(req.http.X-Varnish-Esi-Access==“private”&&
req.http.Cookie~“frontend=”){
散列数据(regsub(req.http.Cookie,“^.*”前端=([^;]*);***$”,“\1”);
}
返回(散列);
}
子vcl_命中{
}
子vcl_取数{
设置req.grace=15s;
设置beresp.http.X-Varnish-Host=req.http.Host;
设置beresp.http.X-Varnish-URL=req.URL;
如果(req.url~“^(/magento2/media/|/magento2/skin/|/magento2/js/|/magento2/)(?:(?:index | litespeed)\.php/)){
unset beresp.http.Vary;
设置beresp.do_gzip=true;
我
[root@ip-172-31-10-??? /]# find -name default.vcl
./etc/varnish/default.vcl
./var/www/html/magento/var/default.vcl
./usr/share/doc/varnish-3.0.5/examples/default.vcl
backend default {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 60s;
.between_bytes_timeout = 60s;
}