【发布时间】:2017-08-24 07:22:18
【问题描述】:
我已经在以下位置设置了一个测试服务器:http://95.85.19.39/,在 Ubuntu 14.04 上运行 varnish 4.1.5(端口 80)和 nginx 1.4.6(端口 8080)。我使用的是 Chrome 57.0.2987.110(64 位)。
Varnish 正在缓存页面,但是当您等待 5 秒以上并点击刷新时,您会看到初始连接,这是为什么呢?当您在 5 秒内点击刷新时,不会有初始连接。
如果我删除 varnish 并仅在 Nginx 上运行服务器,那么我将无法再获得初始连接,所以我认为我的 Varnish 有问题。
有谁知道为什么会发生这种情况,我将如何解决这个问题?
无初始连接
初始连接
nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/sites-enabled/default.conf;
}
default.conf
server {
listen 8080;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.(htaccess|htpasswd|ini|phps|fla|log|sh)$ {
deny all;
}
}
default.vcl
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
}
sub vcl_backend_response {
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
/etc/default/varnish
START=yes
NFILES=131072
MEMLOCK=82000
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
【问题讨论】:
-
@moderator 也许把这个问题转移到serverfault.com会更好?