nginx日志格式的設計
根據開發要求我們要在nginx的日志中列印一些特殊資訊,是以必須自定義一些日志,
#設定user_id的預設值
set $user_id "0";
#設定user_kind的預設值
set $user_kind "-";
#設定uuid的預設值
set $uuid "_";
www.2cto.com
if ( $http_cookie ~* "user_id=([0-9]*)" ){
set $user_id $1;
}
if ( $http_cookie ~* "user_kind=([0-9]*)" ){
set $user_kind $1;
} www.2cto.com
if ( $http_cookie ~* "_uuid=([A-Za-z0-9 ]*)" ){
set $uuid $1;
}
nginx中location子產品的詳細參數介紹
Nginx的Location可以有以下幾個比對:
1. = 嚴格比對這個查詢。如果找到,停止搜尋。
2. ^~ 比對路徑的字首,如果找到,停止搜尋。
3. ~ 為區分大小寫的正則比對
4. ~* 為不區分大小寫比對
5.!~和!~*分别為區分大小寫不比對及不區分大小寫不比對
檔案及目錄比對
* -f和!-f用來判斷是否存在檔案
* -d和!-d用來判斷是否存在目錄
* -e和!-e用來判斷是否存在檔案或目錄
* -x和!-x用來判斷檔案是否可執行
www.2cto.com
一些可用的全局變量
$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri
rewrite後面的flag可以是:
last
break
redirect
permanent
proxy_pass http://localhost:80;
proxy_set_header Host $host;
可以自動改變轉發以後的域名資訊
本文轉自 亮公子 51CTO部落格,原文連結:http://blog.51cto.com/iyull/1864376