0
我想基於某個自定義響應頭來記錄請求主體。所以,假設服務器正在發送TEST-HEADER: value
。現在我必須檢查這個header
的存在,並在nginx中對access_log
做一些操作。
我的配置是如下:
log_format test '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_body"'
'"$sent_http_test_header"';
location/{
proxy_pass http://app_server$request_uri;
access_log logs/access.log main;
set $a $sent_http_test_header;
if ($a) {
access_log logs/host.access1.log test;
}
}
這裏,$sent_http_test_header
或$upstream_http_test_header
變量的值永遠不會設置。所以如果塊永遠不會被執行。
如果我使用$status variable
,它工作正常。
這裏可能有什麼錯誤?
重寫規則在代理之前執行,因此在執行'if'時沒有'$ upstream _...'變量。你可以使用['access_log'](http://nginx.org/r/access_log)指令的nginx 1.7和'if'修飾符。 –
@AlexeyTen有沒有辦法在nginx 1.6.0中做。因爲nginx 1.7是最新版本,我們沒有在生產中使用。我們使用穩定版本1.6。 –
我不知道那樣做 –