nginx配置日志,新增模块

nginx配置请求日志信息

http {

    include       mime.types;

    default_type  application/octet-stream;

    charset utf-8;

    sendfile        on;

    keepalive_timeout  65;

    client_max_body_size 20m;

 log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                                        '"$status" $body_bytes_sent "$http_referer" '

                                        '"$http_user_agent" "$http_x_forwarded_for" '

                                        '"$gzip_ratio" $request_time $bytes_sent $request_length';

 log_format srcache_log '$remote_addr - $remote_user [$time_local] "$request" '

                                '"$status" $body_bytes_sent $request_time $bytes_sent $request_length '

                                '[$upstream_response_time]';

access_log /appl/image/access.log srcache_log;

分为format信息,和具体访问信息,access_log最后的参数可以是配置的任何format信息

新增模块

首先查找当前安装的版本号,和安装了那些模块

/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.6.2

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 

configure arguments: --with-http_stub_status_module

发现了有安装参数,那么直接在安装目录下面

./configure --with-http_stub_status_module  后面放入新的参数等等

make 

即可,不需要make install

然后将新的二进制启动文件拷贝进去

新的在./objs/nginx  这里,需要拷贝到对应位置即可

cp ./objs/nginx //usr/local/nginx/sbin/nginx

我这里安装的就是 --with-http_stub_status_module 配置模块,该模块是为了查看nginx当前并发

这个模块安装后,在对应的server里面新增配置

location /Nginxstatus {

   stub_status on;

   access_log /usr/local/nginx/logs/status.log;

   auth_basic "NginxStatus";

}

这里Nginxstatus 可以随意

然后在浏览器里直接访问

http://192.168.1.223/Nginxstatus

即可

猜你喜欢

转载自lovewen-2004.iteye.com/blog/2343335