Nginx

錯誤 503 服務在 Varnish 上不可用,但 varnishlog 顯示沒有錯誤

  • February 8, 2017

我有一台執行 Varnish 和 nginx 的伺服器。前端網站報503錯誤:

錯誤 503 服務不可用

暫停服務

上師打坐:
XID:317911182

優化記憶體伺服器

這是的內容/etc/varnish/foo.vcl

backend default {
 .host = "127.0.0.1";
 .port = "8080";
 .connect_timeout = 1s;
 .first_byte_timeout = 90s;
 .between_bytes_timeout = 90s;
}

varnishlog顯然沒有問題:

0 CLI          - Rd ping
0 CLI          - Wr 200 19 PONG 1486463718 1.0
0 CLI          - Rd ping
0 CLI          - Wr 200 19 PONG 1486463721 1.0
0 CLI          - Rd ping
0 CLI          - Wr 200 19 PONG 1486463724 1.0
0 CLI          - Rd ping
0 CLI          - Wr 200 19 PONG 1486463727 1.0

但是,在 localhost 的 8080 埠上沒有執行服務:

server# netstat -anp | grep 8080
server# telnet localhost 8080
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

事實上,nginx 日誌在嘗試連接時報告了一個錯誤:

2017/02/07 11:51:11 [error] 2008#0: *188 connect() failed (111: Connection refused) while connecting to upstream, client: 10.2.3.4, server: _, request: "GET /mydir/ HTTP/1.1", upstream: "http://127.0.0.1:8080/mydir/", host: "myhost.example.com"

我可以檢查什麼來進一步解決問題?

以下幾行顯示正常操作 - Varnish 正在檢查它的記憶體是否正常。這是正常現象,與後端連接無關。

    0 CLI            - Rd ping
    0 CLI            - Wr 200 19 PONG 1486473078 1.0

如果後端已配置執行狀況檢查,您將看到類似於以下內容:

清漆日誌輸出:

    0 CLI            - Rd ping
    0 CLI            - Wr 200 19 PONG 1486473075 1.0
    0 Backend_health - boot.default Still sick ------- 1 3 3 0.000000 0.000000
    0 Backend_health - boot.default Still sick ------- 0 3 3 0.000000 0.000000

或者

32771 Timestamp      b Start: 1486473576.634500 0.000000 0.000000
32771 BereqMethod    b GET
32771 BereqURL       b /
32771 BereqProtocol  b HTTP/1.1
32771 BereqHeader    b Host: 127.0.0.1:8080
32771 BereqHeader    b User-Agent: curl/7.51.0
32771 BereqHeader    b Accept: */*
32771 BereqHeader    b X-Forwarded-For: 127.0.0.1
32771 BereqHeader    b Accept-Encoding: gzip
32771 BereqHeader    b X-Varnish: 32771
32771 VCL_call       b BACKEND_FETCH
32771 VCL_return     b fetch
32771 FetchError     b no backend connection

預設.vlc:

backend default {
   .host = "127.0.0.1";
   .port = "8081";
   .probe = {
       .url = "/status";
       .timeout = 60 ms;
       .interval = 10s;
       .window = 3;
       .threshold = 3;
   }
}

引用自:https://unix.stackexchange.com/questions/343125