![](/img/trans.png)
[英]varnish, nginx, & node.js: static nginx html pages with node.js fallback
[英]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.