使用Varnish缓存工具与Node.js和Nginx

时间:2017-11-20 12:26:25

标签: node.js nginx varnish

我在两个不同的端口(3636,4646)上有两台Node.js服务器,我使用Nginx Web服务器作为服务器的反向代理,我的问题是如何将Varnish缓存工具添加到两台服务器上?

的/ etc / nginx的/启用的站点 - / YOURDOMAIN:

upstream app_yourdomain {
    server 127.0.0.1:3636;
    keepalive 8;
}

server {
    listen 0.0.0.0:8080;
    server_name yourdomain.com yourdomain;
    access_log /var/log/nginx/yourdomain.log;
    # pass the request to the node.js server with the correct headers
    # and much more can be added, see nginx config options
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://app_yourdomain/;
      proxy_redirect off;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
 }

的/ etc / nginx的/ /域2启用位点-:

server {
    listen 8080;
    server_name domain2.com;
    access_log /var/log/nginx/domain2.access.log;
    location / {
        proxy_pass    http://127.0.0.1:4646/;
    }
}

清漆配置文件:

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

但是当我使用curl -I http://localhost时,没有任何清漆迹象:

HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Mon, 20 Nov 2017 12:22:17 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Mon, 18 Sep 2017 06:18:46 GMT
Connection: keep-alive
ETag: "59bf6546-264"
Accept-Ranges: bytes

/etc/varnish/default.vcl:

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

我有什么遗失的吗?

1 个答案:

答案 0 :(得分:0)

如果没有看到你的default.vcl,很难说。 也许你有这样的事情:

sub vcl_deliver {
    unset resp.http.Via;
    unset resp.http.X-Varnish;
}    

还要确保拥有正确的后端配置:

backend default {
    .host = "localhost";
    .port = "8080";
}