nginx日志格式的设计



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
   www.2cto.com  
rewrite后面的flag可以是:
last 
break 
redirect 
permanent
 
proxy_pass http://localhost:80;
proxy_set_header Host $host;
 
可以自动改变转发以后的域名信息

相关内容

    暂无相关文章