最近在測試CDN服務質量問題,測試過程中返回了一些不同的狀態碼,當然有一些常用的,也有一些不常用的。最奇葩的是在使用curl命令的時候出現000狀態碼,問了很多同事,對這個000的反應跟新事物是的。
一、生產環境常見的HTTP CODE
生產環境常見的HTTP狀態碼列表(List of HTTP status codes)為:
2XX成功:
200 - OK,服務器成功返回網頁
- Standard response for successful HTTP requests.
3XX重定向:
301 - Moved Permanently(永久跳轉),請求的網頁已永久跳轉到新位置。
- This and all future requests should be directed to the given.
302 - Moved Temporarily(臨時跳轉),請求的網頁已臨時跳轉到新位置。
4XX客戶端錯誤:
403 - Forbidden(禁止訪問),服務器拒絕請求
- forbidden request (matches a deny filter) => HTTP 403
- The request was a legal request, but the server is refusing to respond to it.
404 - Not Found,服務器找不到請求的頁面。
- The requested resource could not be found but may be available again in the future.
5XX服務器錯誤:
500 - Internal Server Error(內部服務器錯誤)
- internal error in haproxy => HTTP 500
- A generic error message, given when no more specific message is suitable.
502 - Bad Gateway(壞的網關),一般是網關服務器請求后端服務時,后端服務沒有按照http協議正確返回結果。
- the server returned an invalid or incomplete response => HTTP 502
- The server was acting as a gateway or proxy and received an invalid response from the upstream server.
503 - Service Unavailable(服務當前不可用),可能因為超載或停機維護。
- no server was available to handle the request => HTTP 503
- The server is currently unavailable (because it is overloaded or down for maintenance).
504 - Gateway Timeout(網關超時),一般是網關服務器請求后端服務時,后端服務沒有在特定的時間內完成服務。
- the server failed to reply in time => HTTP 504
- The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
二、curl奇怪的返回值000。
經過測試發現在curl的時候出現000的情況有如下幾種:
1.Failed DNS resolution (6)
$ curl -w "%{http_code}\n" http://example.invalid/ ; echo "Exit code: $?"
000
curl: (6) Could not resolve host: example.invalid
Exit code: 6
2.Connection refused (7)
$ curl -w "%{http_code}\n" http://localhost:81/ ; echo "Exit code: $?"
000
curl: (7) Failed to connect to localhost port 81: Connection refused
Exit code: 7
Connection timed out (28)
$ curl -w "%{http_code}\n" -m 5 http://10.255.255.1/ ; echo "Exit code: $?"
000
curl: (28) Connection timed out after 5001 milliseconds
Exit code: 28
Server actually returns 000 for some reason (0)
開啟一個監聽端口:
nc -l -p 65535 & <<EOF
HTTP/1.1 000 Fake Status Code
Content-Length: 0
Connection: close
EOF
客戶端請求:
$ curl -w "%{http_code}\n" http://localhost:65535/ ; echo "Exit code: $?"
000
Exit code: 0
*注釋:一般情況下遇到000,默認考慮為200,正常。
在測試過程中打印了000時的錯誤信息,錯誤為:Connection timed out。使用curl時,參數:-sS ,然后將curl的錯誤 2>> /tmp/err.log。
參考文章:
wikipedia:https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
http://superuser.com/questions/501690/curl-http-code-of-000