I have two Node.js server on two different ports(3636, 4646), I used Nginx web server as a reverse proxy for my servers , my problem is how to add Varnish cache tool to both servers?
/etc/nginx/sites-enabled/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/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/;
}
}
varnish config file:
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
but when I use curl -I http://localhost
there is no sign of varnish :
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";
}
Is there anything am I missing?
That's hard to tell without seeing your default.vcl. Maybe you have something like this:
sub vcl_deliver {
unset resp.http.Via;
unset resp.http.X-Varnish;
}
Also make sure to have the correct backend config:
backend default {
.host = "localhost";
.port = "8080";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.