Skip to content

Instantly share code, notes, and snippets.

@boneyao
Created April 22, 2016 11:17
Show Gist options
  • Save boneyao/b847085ead6b6c12aae81861955d5274 to your computer and use it in GitHub Desktop.
Save boneyao/b847085ead6b6c12aae81861955d5274 to your computer and use it in GitHub Desktop.
nginx_format = '$remote_addr => $upstream_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_cookie" $request_time $upstream_response_time "$proxy_add_x_forwarded_for" $upstream_cache_status'
_map = {
'$remote_addr': '%h',
'$upstream_addr': '%^', #nq
'$time_local': '%d:%t +0800',
'$request': '%r',
'$status': '%s',
'$body_bytes_sent': '%b',
'$http_referer': '%R',
"$http_user_agent": '%u',
"$http_cookie": "%^",
"$request_time": "%t",
"$upstream_response_time": "%t",
"$proxy_add_x_forwarded_for": "%^",
"$upstream_cache_status": '%^'
}
for n, g in _map.items():
nginx_format = nginx_format.replace(n, g, 1)
print nginx_format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment