簡體   English   中英

將Varnish緩存工具與Node.js和Nginx結合使用

[英]Use Varnish cache tool with Node.js and Nginx

我在兩個不同的端口(3636、4646)上有兩個Node.js服務器,我使用Nginx Web服務器作為服務器的反向代理,我的問題是如何向兩個服務器添加Varnish緩存工具?

/ etc / nginx / sites-enabled /您的域:

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 / sites-enabled / domain2:

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";
}

我有什么想念的嗎?

如果沒有看到您的default.vcl,這很難告訴。 也許你有這樣的事情:

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

另外,請確保具有正確的后端配置:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM