I’m getting stuck trying to implement Varnish 4.0 on Virtual Hosts set up using nginx. I have tried to configure the backend per my reading but I can’t seem to get varnish to work on anything but the main IP address. For this example, I will use site1*com and 12:34:56:78 for my IP address.
Also, I had to change the . to * due to reputation points and I'm not trying to link an address, just express what i have typed.
I have this in nginx.conf:
…
server {
listen 8080;
root /usr/share/nginx/html;
location / {
}
…
and I have this typed in varnish.params:
…
#VARNISH_LISTEN_ADDRESS=“12:34:56:78” (I know this is commented out)
VARNISH_LISTEN_PORT=80
# Admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS=12:34:56:78
VARNISH_ADMIN_LISTEN_PORT=6082
In default.vcl I have typed:
…
backend default {
.host = “127.0.0.1";
.port = "8080";
}
backend site1 {
.host = “127.0.0.1";
.port = "8080";
}
…
…
sub vcl_recv {
if (req.http.host ~ "www*site1*com$")
set req.http.host = "127.0.0.1";
set req.backend_hint = smith;
}
else {
set req.http.host = "127.0.0.1";
set req.backend_hint = default;
}
Finally, for my site1*com*conf file (for the virtual host file) I have set up the following:
…
server {
listen 127.0.0.1:8080;
server_name site1.com www*site1*com;
…
From here, if I type curl -I http://12:34:56:78 I get the following:
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 15 Jan 2016 15:09:51 GMT
Content-Type: text/html
Content-Length: 3700
Last-Modified: Sun, 04 Oct 2015 07:53:44 GMT
ETag: "5610db08-e74"
X-Varnish: 2
Age: 0
Via: 1.1 varnish-v4
Connection: keep-alive
Awesome. But then when I type curl -I http://www*site1*com I get the following:
HTTP/1.1 200 OK
Server: nginx/1.0.15
Date: Fri, 15 Jan 2016 22:57:30 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Keep-Alive: timeout=15
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 4918
Expires: -1
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ARR/2.5
X-Powered-By: ASP.NET
No varnish. As a test, I also tried curl -I http://site1*com and got the following:
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Fri, 15 Jan 2016 15:10:16 GMT
Content-Type: text/html
Connection: keep-alive
Keep-Alive: timeout=15
Content-Length: 154
To me, it seems like varnish is installed and works on the IP address, but something is getting lost in translation when I go to the virtual host. I’m hoping its a simple error in my syntax or in how I’m testing, but I am stumped.
Any help would be so greatly appreciated.