在nginx上使用虚拟主机配置Varnish-4

在nginx上使用虚拟主机配置Varnish-4,nginx,configuration,virtualhost,varnish,virtual-hosts,Nginx,Configuration,Virtualhost,Varnish,Virtual Hosts,我一直在尝试在使用nginx设置的虚拟主机上实现Varnish 4.0。我试图根据我的阅读配置后端,但除了主IP地址外,我似乎无法让varnish处理任何事情。对于本例,我将使用site1*com和12:34:56:78作为我的IP地址 另外,我还得换衣服。由于信誉问题,我不想链接地址,只想表达我键入的内容 我在nginx.conf中有: … server { listen 8080; root /usr/share/nginx/html; location / { } …

我一直在尝试在使用nginx设置的虚拟主机上实现Varnish 4.0。我试图根据我的阅读配置后端,但除了主IP地址外,我似乎无法让varnish处理任何事情。对于本例,我将使用site1*com和12:34:56:78作为我的IP地址

另外,我还得换衣服。由于信誉问题,我不想链接地址,只想表达我键入的内容

我在nginx.conf中有:

…
server {
listen  8080;
root         /usr/share/nginx/html;
location / {
}
…
我在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
在default.vcl中,我键入了:

…
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;
}
最后,对于我的site1*com*conf文件(对于虚拟主机文件),我设置了以下内容:

…
server {
listen     127.0.0.1:8080;
server_name site1.com www*site1*com;
…
  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
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
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
从这里,如果我输入curl-I,我会得到以下结果:

…
server {
listen     127.0.0.1:8080;
server_name site1.com www*site1*com;
…
  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
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
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
太棒了。但是,当我键入curl-I*site1*com时,我会得到以下结果:

…
server {
listen     127.0.0.1:8080;
server_name site1.com www*site1*com;
…
  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
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
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
没有清漆。作为测试,我还尝试了curl-I*com,得到了以下结果:

…
server {
listen     127.0.0.1:8080;
server_name site1.com www*site1*com;
…
  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
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
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
对我来说,似乎varnish已经安装并在IP地址上工作,但当我转到虚拟主机时,在翻译过程中有些东西丢失了。我希望这是我的语法或测试方式中的一个简单错误,但我被难住了


任何帮助都将不胜感激。

我为不得不更改密码提前道歉。至*。这使阅读有点困难。我也可以做得更好。今天晚些时候我有时间时,我会尝试编辑它。但我知道我把一个令人困惑的话题弄得有点混乱,再一次抱歉。作为第二条评论,我注意到当我启用ngx_pagespeed时,它也在12:34:56:78工作,但在www*site1*com上不工作。因此,可能是我设置服务器块时出错了?您的www*是否解析为IPv4或IPv6 ip?看起来您可能正在侦听ipV6地址(假设这是12:34..),但不清楚您是否正在侦听该站点的ipV4版本,nginx可能正在执行此操作。我为必须更改此地址提前道歉。至*。这使阅读有点困难。我也可以做得更好。今天晚些时候我有时间时,我会尝试编辑它。但我知道我把一个令人困惑的话题弄得有点混乱,再一次抱歉。作为第二条评论,我注意到当我启用ngx_pagespeed时,它也在12:34:56:78工作,但在www*site1*com上不工作。因此,可能是我设置服务器块时出错了?您的www*是否解析为IPv4或IPv6 ip?似乎您正在监听的是ipV6地址(假设这是12:34..),但不清楚您是否正在监听该站点的ipV4版本,nginx可能正在执行此操作。