- 浏览: 564752 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (618)
- java (109)
- Java web (43)
- javascript (52)
- js (15)
- 闭包 (2)
- maven (8)
- 杂 (28)
- python (47)
- linux (51)
- git (18)
- (1)
- mysql (31)
- 管理 (1)
- redis (6)
- 操作系统 (12)
- 网络 (13)
- mongo (1)
- nginx (17)
- web (8)
- ffmpeg (1)
- python安装包 (0)
- php (49)
- imagemagic (1)
- eclipse (21)
- django (4)
- 学习 (1)
- 书籍 (1)
- uml (3)
- emacs (19)
- svn (2)
- netty (9)
- joomla (1)
- css (1)
- 推送 (2)
- android (6)
- memcached (2)
- docker、 (0)
- docker (7)
- go (1)
- resin (1)
- groovy (1)
- spring (1)
最新评论
-
chokee:
...
Spring3 MVC 深入研究 -
googleyufei:
很有用, 我现在打算学学Python. 这些资料的很及时.
python的几个实用网站(转的) -
hujingwei1001:
太好了找的就是它
easy explore -
xiangtui:
例子举得不错。。。学习了
java callback -
幻影桃花源:
太好了,謝謝
Spring3 MVC 深入研究
原文地址:http://gunner.me/archives/363
从Apache切到Nginx需要保持日志格式统一,以便兼容之前的数据统计脚本
现在Apache的日志格式为:
1
LogFormat "%h %t %m %U %q %>s %{HEAD}i %D"
说明:
%h:客户端IP地址
%t:时间(标准英语格式)
%m:请求的方法(GET,POST)
%U:请求的URL路径,不包含查询字符串
%q:查询字符串
%>s:请求的最终状态
%{HEAD}i:请求头信息
%D:服务器处理请求所用时间,微秒为单位
对应的Nginx日志格式为:
1
2
3
log_format main '$remote_addr [$time_local] $request_method $uri '
'$query_string $status '
'$http_head $request_time ';
其中Apache里的%{HEAD}i这个参数里的HEAD是在程序里自定义了一个header,在Nginx里面取这个HEAD用到的是$http_head参数,head就是自定义的header名称HEAD, Nginx里面需要小写,在这里走了不少弯路。
用firebug获取http header,如下图
Snip20140828_3
有两部分内容,一个是响应头,一个是请求头,请求头是客户端发送给服务器的,包括Requst Line及HTTP Header,响应头是服务器返回给客户端的,包括Status Line及HTTP Header。关于http header的说明,这里有一篇很好的文章可以参考。
在Nginx里面可以用$upstream_http_’header名称’来获取响应头信息,比如$upstream_http_content_type将会获取到类似text/html; charset=utf-8的内容,说明返回的文件类型及编码格式。在我的需求中是要获取自定义的请求头的内容,需要使用$sent_http_’自定义header名称’来获取,但我测试过程中没有取到,用$http_’自定义header名称’才取到,也许和Nginx版本有关,我的版本是1.4.2。
另外,测试过程中用的是firefox的poster插件,可以自定义请求头,截图如下:
Snip20140828_4
自定义一个header,然后输入URL,点GET即可发送带有自定义header的请求,在服务器端查看日志可以看到取到了‘AAAAAAAAAAAAAAAAAAAAAA’.
附nginx.org里关于log_format参数的说明,英文不好,看着费劲。
The ngx_http_core_module module supports embedded variables with names matching the Apache Server variables. First of all, these are variables representing client request header fields, such as $http_user_agent, $http_cookie, and so on. Also there are other variables:
$arg_name
argument name in the request line
$args
arguments in the request line
$binary_remote_addr
client address in a binary form, value’s length is always 4 bytes
$body_bytes_sent
number of bytes sent to a client, not counting the response header; this variable is compatible with the “%B” parameter of the mod_log_config Apache module
$bytes_sent
number of bytes sent to a client (1.3.8, 1.2.5)
$connection
connection serial number (1.3.8, 1.2.5)
$connection_requests
current number of requests made through a connection (1.3.8, 1.2.5)
$content_length
“Content-Length” request header field
$content_type
“Content-Type” request header field
$cookie_name
the name cookie
$document_root
root or alias directive’s value for the current request
$document_uri
same as $uri
$host
in this order of precedence: host name from the request line, or host name from the “Host” request header field, or the server name matching a request
$hostname
host name
$http_name
arbitrary request header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores
$https
“on” if connection operates in SSL mode, or an empty string otherwise
$is_args
“?” if a request line has arguments, or an empty string otherwise
$limit_rate
setting this variable enables response rate limiting; see limit_rate
$msec
current time in seconds with the milliseconds resolution (1.3.9, 1.2.6)
$nginx_version
nginx version
$pid
PID of the worker process
$pipe
“p” if request was pipelined, “.” otherwise (1.3.12, 1.2.7)
$proxy_protocol_addr
client address from the PROXY protocol header, or an empty string otherwise (1.5.12)
The PROXY protocol must be previously enabled by setting the proxy_protocol parameter in the listen directive.
$query_string
same as $args
$realpath_root
an absolute pathname corresponding to the root or alias directive’s value for the current request, with all symbolic links resolved to real paths
$remote_addr
client address
$remote_port
client port
$remote_user
user name supplied with the Basic authentication
$request
full original request line
$request_body
request body
The variable’s value is made available in locations processed by the proxy_pass, fastcgi_pass, uwsgi_pass, and scgi_pass directives.
$request_body_file
name of a temporary file with the request body
At the end of processing, the file needs to be removed. To always write the request body to a file, client_body_in_file_only needs to be enabled. When the name of a temporary file is passed in a proxied request or in a request to a FastCGI/uwsgi/SCGI server, passing the request body should be disabled by the proxy_pass_request_body off, fastcgi_pass_request_body off, uwsgi_pass_request_body off, or scgi_pass_request_body off directives, respectively.
$request_completion
“OK” if a request has completed, or an empty string otherwise
$request_filename
file path for the current request, based on the root or alias directives, and the request URI
$request_length
request length (including request line, header, and request body) (1.3.12, 1.2.7)
$request_method
request method, usually “GET” or “POST”
$request_time
request processing time in seconds with a milliseconds resolution (1.3.9, 1.2.6); time elapsed since the first bytes were read from the client
$request_uri
full original request URI (with arguments)
$scheme
request scheme, “http” or “https”
$sent_http_name
arbitrary response header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores
$server_addr
an address of the server which accepted a request
Computing a value of this variable usually requires one system call. To avoid a system call, the listen directives must specify addresses and use the bind parameter.
$server_name
name of the server which accepted a request
$server_port
port of the server which accepted a request
$server_protocol
request protocol, usually “HTTP/1.0” or “HTTP/1.1”
$status
response status (1.3.2, 1.2.2)
$tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, $tcpinfo_rcv_space
information about the client TCP connection; available on systems that support the TCP_INFO socket option
$time_iso8601local
time in the ISO 8601 standard format (1.3.12, 1.2.7)
$time_local
local time in the Common Log Format (1.3.12, 1.2.7)
$uri
current URI in request, normalized
The value of $uri may change during request processing, e.g. when doing internal redirects, or when using index files.
参考:http://blog.51yip.com/apachenginx/1277.html
从Apache切到Nginx需要保持日志格式统一,以便兼容之前的数据统计脚本
现在Apache的日志格式为:
1
LogFormat "%h %t %m %U %q %>s %{HEAD}i %D"
说明:
%h:客户端IP地址
%t:时间(标准英语格式)
%m:请求的方法(GET,POST)
%U:请求的URL路径,不包含查询字符串
%q:查询字符串
%>s:请求的最终状态
%{HEAD}i:请求头信息
%D:服务器处理请求所用时间,微秒为单位
对应的Nginx日志格式为:
1
2
3
log_format main '$remote_addr [$time_local] $request_method $uri '
'$query_string $status '
'$http_head $request_time ';
其中Apache里的%{HEAD}i这个参数里的HEAD是在程序里自定义了一个header,在Nginx里面取这个HEAD用到的是$http_head参数,head就是自定义的header名称HEAD, Nginx里面需要小写,在这里走了不少弯路。
用firebug获取http header,如下图
Snip20140828_3
有两部分内容,一个是响应头,一个是请求头,请求头是客户端发送给服务器的,包括Requst Line及HTTP Header,响应头是服务器返回给客户端的,包括Status Line及HTTP Header。关于http header的说明,这里有一篇很好的文章可以参考。
在Nginx里面可以用$upstream_http_’header名称’来获取响应头信息,比如$upstream_http_content_type将会获取到类似text/html; charset=utf-8的内容,说明返回的文件类型及编码格式。在我的需求中是要获取自定义的请求头的内容,需要使用$sent_http_’自定义header名称’来获取,但我测试过程中没有取到,用$http_’自定义header名称’才取到,也许和Nginx版本有关,我的版本是1.4.2。
另外,测试过程中用的是firefox的poster插件,可以自定义请求头,截图如下:
Snip20140828_4
自定义一个header,然后输入URL,点GET即可发送带有自定义header的请求,在服务器端查看日志可以看到取到了‘AAAAAAAAAAAAAAAAAAAAAA’.
附nginx.org里关于log_format参数的说明,英文不好,看着费劲。
The ngx_http_core_module module supports embedded variables with names matching the Apache Server variables. First of all, these are variables representing client request header fields, such as $http_user_agent, $http_cookie, and so on. Also there are other variables:
$arg_name
argument name in the request line
$args
arguments in the request line
$binary_remote_addr
client address in a binary form, value’s length is always 4 bytes
$body_bytes_sent
number of bytes sent to a client, not counting the response header; this variable is compatible with the “%B” parameter of the mod_log_config Apache module
$bytes_sent
number of bytes sent to a client (1.3.8, 1.2.5)
$connection
connection serial number (1.3.8, 1.2.5)
$connection_requests
current number of requests made through a connection (1.3.8, 1.2.5)
$content_length
“Content-Length” request header field
$content_type
“Content-Type” request header field
$cookie_name
the name cookie
$document_root
root or alias directive’s value for the current request
$document_uri
same as $uri
$host
in this order of precedence: host name from the request line, or host name from the “Host” request header field, or the server name matching a request
$hostname
host name
$http_name
arbitrary request header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores
$https
“on” if connection operates in SSL mode, or an empty string otherwise
$is_args
“?” if a request line has arguments, or an empty string otherwise
$limit_rate
setting this variable enables response rate limiting; see limit_rate
$msec
current time in seconds with the milliseconds resolution (1.3.9, 1.2.6)
$nginx_version
nginx version
$pid
PID of the worker process
$pipe
“p” if request was pipelined, “.” otherwise (1.3.12, 1.2.7)
$proxy_protocol_addr
client address from the PROXY protocol header, or an empty string otherwise (1.5.12)
The PROXY protocol must be previously enabled by setting the proxy_protocol parameter in the listen directive.
$query_string
same as $args
$realpath_root
an absolute pathname corresponding to the root or alias directive’s value for the current request, with all symbolic links resolved to real paths
$remote_addr
client address
$remote_port
client port
$remote_user
user name supplied with the Basic authentication
$request
full original request line
$request_body
request body
The variable’s value is made available in locations processed by the proxy_pass, fastcgi_pass, uwsgi_pass, and scgi_pass directives.
$request_body_file
name of a temporary file with the request body
At the end of processing, the file needs to be removed. To always write the request body to a file, client_body_in_file_only needs to be enabled. When the name of a temporary file is passed in a proxied request or in a request to a FastCGI/uwsgi/SCGI server, passing the request body should be disabled by the proxy_pass_request_body off, fastcgi_pass_request_body off, uwsgi_pass_request_body off, or scgi_pass_request_body off directives, respectively.
$request_completion
“OK” if a request has completed, or an empty string otherwise
$request_filename
file path for the current request, based on the root or alias directives, and the request URI
$request_length
request length (including request line, header, and request body) (1.3.12, 1.2.7)
$request_method
request method, usually “GET” or “POST”
$request_time
request processing time in seconds with a milliseconds resolution (1.3.9, 1.2.6); time elapsed since the first bytes were read from the client
$request_uri
full original request URI (with arguments)
$scheme
request scheme, “http” or “https”
$sent_http_name
arbitrary response header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores
$server_addr
an address of the server which accepted a request
Computing a value of this variable usually requires one system call. To avoid a system call, the listen directives must specify addresses and use the bind parameter.
$server_name
name of the server which accepted a request
$server_port
port of the server which accepted a request
$server_protocol
request protocol, usually “HTTP/1.0” or “HTTP/1.1”
$status
response status (1.3.2, 1.2.2)
$tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, $tcpinfo_rcv_space
information about the client TCP connection; available on systems that support the TCP_INFO socket option
$time_iso8601local
time in the ISO 8601 standard format (1.3.12, 1.2.7)
$time_local
local time in the Common Log Format (1.3.12, 1.2.7)
$uri
current URI in request, normalized
The value of $uri may change during request processing, e.g. when doing internal redirects, or when using index files.
参考:http://blog.51yip.com/apachenginx/1277.html
发表评论
-
Nginx模块fastcgi_cache的几个注意点
2014-09-17 11:01 596原文地址:http://www.cnxct ... -
[nginx] nginx缓存cache的几种方式
2014-09-15 13:57 804原文地址:http://bbs.linuxtone.org/t ... -
NGINX的流媒体插件 nginx-rtmp-module
2014-09-15 12:03 646http://www.oschina.net/p/nginx- ... -
nginx 自定义 header
2014-09-15 11:56 789$http_HEADER The value of the H ... -
nginx反向代理proxy_set_header自定义header头无效
2014-09-15 11:52 1359原文地址:http://www.ttlsa.com/nginx ... -
nginx 自定义协议 扩展模块开发
2014-09-15 09:33 993原文地址:http://blog.chin ... -
Nginx模块开发入门
2014-09-14 10:05 629原文地址:http://kb.cnblogs.com/page ... -
nginx log_format 记录自定义header信息
2014-09-12 17:53 2221原文地址:http://notelifes.com/2013/ ... -
nginx log 记录请求的头信息
2014-09-12 14:44 1077记录访问的log,为了在 ... -
nginx官网文档地址
2014-09-10 10:33 571原文地址:http://wiki.nginx.org/Ngin ... -
Nginx配置反向代理时cache缓存的使用方法
2014-09-10 10:32 905原文地址:http://www.server110.com/n ... -
Windows下Nginx+PHP5(FastCgi)安装配置详解
2014-08-25 16:46 854源文地址:http://www.china ... -
nginx 多域名虚拟主机配置 (nginx如何绑定多个域名)
2014-08-25 14:33 392原文地址:http://wenku.baidu.com/lin ... -
实例讲解Nginx下的rewrite规则
2014-06-17 14:44 782一.正则表达式匹配, ... -
使用nginx的proxy_cache做网站缓存
2014-02-25 18:08 808使用nginx的proxy_cache做网站缓存 2012年1 ... -
nginx cache静态化+tmpfs 高性能cdn方案 原创-胡志广
2014-02-25 18:04 849nginx cache静态化+tmpfs 高性能cdn方案 原 ...
相关推荐
4. 头部处理:在解析请求头时,Nginx会查找匹配的内部处理函数,这些函数定义在`ngx_http_header_t`结构体数组中。例如,对于"Host"头,Nginx会调用相应的处理函数来处理主机名信息。 5. 遍历循环:`ngx_...
Lua-Nginx-Module,简称lua-nginx-module,是Nginx服务器的一个重要扩展模块,它将强大的Lua脚本语言集成到Nginx中,允许用户在Nginx配置文件中直接编写Lua代码,极大地增强了Nginx的功能性和灵活性。版本0.10.13是...
在IT行业中,Nginx和Resin是两种广泛使用的服务器软件。Nginx以其高性能、低内存占用和反向代理能力而闻名,而Resin则是一款基于Java的Servlet容器,适用于处理Java Web应用程序。将Nginx与Resin集成可以充分利用...
在配置中指定静态文件目录,Nginx会直接返回文件,而无需经过后端应用服务器。 ### 九、安全注意事项 确保在生产环境中配置HTTPS以加密传输,使用`listen 443 ssl;`并添加SSL证书配置。同时,限制对敏感目录的访问...
以上仅是Nginx配置的冰山一角,实际应用中还可以结合正则表达式、if条件语句、自定义模块等实现更多高级功能。理解并熟练掌握这些基本配置,能够帮助运维人员更好地管理和优化Nginx服务器,提升网站性能和稳定性。
- **access_log**: 记录访问日志,格式可自定义。 - **error_log**: 记录错误日志,级别包括debug、info、notice、warn、error。 - **location**: 配置URL匹配规则,如`location / { ... }`匹配所有请求。 - **proxy...
解压"nginx-若依-定值配置.zip"文件后,你会得到一个预先配置好的Nginx配置,只需适当修改以适应你的环境,然后在Nginx中加载或替换当前配置即可。记住,正确配置和管理Nginx对于提供稳定、高效的Web服务至关重要。
- Nginx的核心配置文件是`nginx.conf`,在解压后的目录中可以找到。这个文件定义了Nginx的行为,包括监听的端口、服务器块(server blocks)等。 - 在Windows上,你可能需要修改默认的监听端口,因为某些系统服务...
Nginx的日志记录可以自定义,包括添加或修改请求头信息。例如,如果你想记录用户的User-Agent,可以这样做: ```nginx log_format custom '$remote_addr - $remote_user [$time_local] ' '"$request" $status $...
Nginx的日志记录功能强大且灵活,可以自定义日志格式,通过`access_log`和`error_log`指令控制日志输出。 **十、健康检查** 通过`proxy_next_upstream`和`proxy_set_header`等指令,Nginx可以对后端服务器进行健康...
在Linux系统中,Nginx的安装通常通过包管理器进行,例如在Ubuntu或Debian上使用`apt-get`,在CentOS或Fedora上使用`yum`或`dnf`。首先,更新包列表,然后安装Nginx: ```bash sudo apt-get update sudo apt-get ...
在很多场景下,Nginx被用作替代Apache服务器的选择,尤其是在高流量网站和需要负载均衡的环境中。本实战指南旨在探讨如何通过Nginx实现高性能的Web服务,以提升网站的响应速度和稳定性。 一、Nginx与Apache的性能...
在Ubuntu或Debian系统中,可以使用apt-get命令来安装Nginx: ``` sudo apt-get update sudo apt-get install nginx ``` 2. **CentOS/RHEL系统安装** 对于基于RPM的系统,如CentOS或RHEL,使用yum命令: ``` ...
Nginx 作为一个流行的 Web 服务器软件,在实际应用中经常会遇到各种错误。这些错误可能来自于配置不当、资源限制、网络连接问题等多方面。为了帮助开发者和运维人员更好地解决这些问题,本文将总结常见的 Nginx 错误...
模块定义和模块注册则是在模块开发中,将模块功能加入到nginx中的过程,这部分涵盖了如何使模块运行以及与nginx核心通信的方法。 处理模块、过滤模块和负载均衡模块的分析部分,详细地阐述了各个模块类型的具体实现...
在上述示例中,`balancer:$upstream_addr`会记录请求被转发到哪个上游服务器。 文档中的"如何设置nginx日志格式来查看负载分担结果.docx"应该包含了更详细的信息,教你如何通过调整日志格式来追踪和分析负载均衡...
`log_by_lua`可在日志记录阶段执行,允许自定义日志格式和内容。 此外,`init_by_lua*`系列指令在Nginx工作进程启动时执行,常用于全局变量的初始化和配置。`init_worker_by_lua*`则在每个工作进程启动时运行,适合...
Nginx默认记录访问日志,可以在`http`或`server`块中自定义日志格式: ```nginx access_log /var/log/nginx/access.log custom; log_format custom '$remote_addr - $remote_user [$time_local] "$request" ' '$...
它的设计目标是高并发、低内存占用,使得Nginx在处理静态内容和作为反向代理时表现出色。本文将深入探讨Nginx的核心特性、配置、优化策略以及与Java应用程序的集成。 1. **Nginx核心特性** - **事件驱动模型**:...
在这个场景中,我们利用Flume来从Nginx服务器收集日志,并将这些日志数据导入到新版的Hive数据仓库中。下面将详细阐述这个过程涉及的技术要点。 首先,Nginx是一款高性能的HTTP和反向代理服务器,它的日志记录了...