Nginx

清漆埠設置

  • July 14, 2016

我在安裝 Varnish 時遇到了問題。這是 Varnish 之前的樣子:Nginx 反向代理 + Apache + Centos 6 64 Bit

我安裝了 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.conf

#
# 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;
       }

我對 localhost 和 domain.com 使用了curl -l命令。我應該如何設置埠和 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

有什麼問題?一切似乎都是正確的。刪除 Nginx。然後重新啟動 Apache,然後重新啟動 Varnish。

引用自:https://serverfault.com/questions/789810