在nginx

时间:2016-01-15 15:25:55

标签: nginx configuration virtualhost varnish virtual-hosts

我试图在使用nginx设置的虚拟主机上实现Varnish 4.0时遇到困难。我试图按照我的阅读配置后端,但我似乎无法使用varnish来处理除主IP地址之外的任何内容。对于此示例,我将使用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;
…

从这里开始,如果我输入curl -I http://12:34:56:78,我会得到以下内容:

  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

真棒。但是当我输入curl -I http://www * site1 * com时,我得到以下内容:

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

没有清漆。作为测试,我也尝试了curl -I http://site1 * com并获得以下内容:

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地址上工作,但是当我去虚拟主机时,翻译中的某些内容会丢失。我希望我的语法或我的测试方式有一个简单的错误,但我很难过。

任何帮助都会非常感激。

0 个答案:

没有答案