我在安装 Varnish 时卡住了。这是安装 Varnish 之前的样子:Nginx 反向代理 + Apache + Centos 6 64 位
我安装了 Varnish,并按如下方式设置端口。首先,我们要删除 Nginx 反向代理并完全切换到 Apache。因为 Varnish 目前无法正常工作。
默认的VCL
backend default {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 60s;
.connect_timeout = 300s;
}
漆
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-u varnish -g varnish \
-S /etc/varnish/secret \
-s file,/var/lib/varnish/varnish_storage.bin,256m"
httpd配置文件
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 8080
nginx-vhosts.conf
server {
listen 176.xx.xx.xx:80;
listen 127.0.0.1:80;
#listen [::1]:80;
server_name $hostname 176.xx.xx.xx;
root /var/www/html;
index index.html index.htm index.php;
include /etc/nginx/nginx-userdir.conf;
location / {
access_log off;
proxy_pass http://176.xx.xx.xx:8080;
proxy_set_header X-Client-IP $remote_addr;
proxy_set_header X-Accel-Internal /nginx_static_files;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
我用的是curl -llocalhost 和 domain.com 的命令。我应该如何设置端口和 IP 才能使 Varnish 正常工作?
本地主机
[root@ns1 ~]# curl -I http://localhost
HTTP/1.1 200 OK
Date: Thu, 14 Jul 2016 11:35:43 GMT
Server: Apache/2
X-Powered-By: W3 Total Cache/0.9.4.1
Link: <http://******.com/wp-json/>; rel="https://api.w.org/"
Cache-Control: max-age=3600
Expires: Thu, 14 Jul 2016 12:35:43 GMT
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Varnish: 2
Age: 0
Via: 1.1 varnish-v4
X-Cache: MISS
Connection: keep-alive
我的域名.com
[root@ns1 ~]# curl -I http://my domain.com
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 14 Jul 2016 11:36:07 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 344285
Connection: close
Vary: Accept-Encoding
Last-Modified: Thu, 14 Jul 2016 11:30:57 GMT
ETag: "540dd-53796d5f31b86"
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Cache-Control: public, must-revalidate, proxy-revalidate
Expires: Thu, 14 Jul 2016 12:30:57 GMT
X-Powered-By: W3 Total Cache/0.9.4.1
Pragma: public
答案1
有什么问题?一切似乎都正确。删除 Nginx。然后重新启动 Apache,然后重新启动 Varnish。