nginx配置好負載分擔後,測試的時候,如何檢視負載分擔情況:通過設定nginx日志顯示:
nginx伺服器日志相關指令主要有兩條,一條是log_format,用來設定日志格式,另外一條是access_log,用來指定日志檔案的存放路徑、格式和緩存大小,一般在nginx的配置檔案中日記配置(/usr/local/nginx/conf/nginx.conf)。
nginx的log_format有很多可選的參數用于訓示伺服器的活動狀态,預設的是:
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" ' '"$http_user_agent"
"$http_x_forwarded_for"';
想要記錄更詳細的資訊需要自己設定log_format,具體可設定的參數格式及說明如下:
參數 | 說明 | 示例 |
$remote_addr | 用戶端位址 | 211.28.65.253 |
$remote_user | 用戶端使用者名稱 | -- |
$time_local | 通路時間和時區 | 18/Jul/2012:17:00:01 +0800 |
$request | 請求的URI和HTTP協定 | "GET /article-10000.html HTTP/1.1" |
$http_host | 請求位址,即浏覽器中你輸入的位址(IP或域名) | www.it300.com 192.168.100.100 |
$status | HTTP請求狀态 | 200 |
$upstream_status | upstream狀态 | |
$body_bytes_sent | 發送給用戶端檔案内容大小 | 1547 |
$http_referer | url跳轉來源 | https://www.baidu.com/ |
$http_user_agent | 使用者終端浏覽器等資訊 | "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; GTB7.0; .NET4.0C; |
$ssl_protocol | SSL協定版本 | TLSv1 |
$ssl_cipher | 交換資料中的算法 | RC4-SHA |
$upstream_addr | 背景upstream的位址,即真正提供服務的主機位址; 當ngnix做負載均衡時,可以檢視背景提供真實服務的裝置 | 10.10.10.100:80 |
$request_time | 整個請求的總時間 | 0.205 |
$upstream_response_time | 請求過程中,upstream響應時間 | 0.002 |