日志产生演示
准备nginx环境
安装gcc编译器
# yum -y install gcc
安装pcre库:nginx的http模块使用pcre来解析正则表达式
# yum install -y pcre pcre-devel
nginx使用zlib对http包的内容进行gzip
# yum install -y zlib zlib-devel
安装openssl
# yum install -y openssl openssl-devel
安装nginx
编译安装
$ wget http://nginx.org/download/nginx-1.9.9.tar.gz
$ tar -zxvf nginx-1.9.9.tar.gz /var/soft
在nginx解压目录下编译安装
# ./configure
# make
# make install
配置nginx
切到安装目录
# cd /usr/local/nginx
# vi conf/nginx.conf
启动
启动
# ./sbin/nginx
是否启动
# ps -ef | grep nginx
显示如下
root 23030 1 0 01:37 ? 00:00:00 nginx: master process ./sbin/nginx
nobody 23031 23030 0 01:37 ? 00:00:00 nginx: worker process
root 23035 20666 0 01:38 pts/1 00:00:00 grep --color=auto nginx
产生访问日志
# tail -f /usr/local/nginx/logs/access.log
浏览器访问服务器
sing-node
配置nginx
日志输出为json格式
log_format log_json '{"access_time": "$time_local", '
'"remote_addr": "$remote_addr", '
'"host": "$host", '
'"scheme": "$scheme", '
'"request_uri": "$request_uri", '
'"request_method": "$request_method", '
'"http_cookie": "$http_cookie", '
'"args": "$args", '
'"status_code": $status, '
'"body_bytes_sent": $body_bytes_sent, '
'"agent": "$http_user_agent", '
'"x_forwarded":$http_x_forwarded_for", '
'"request_time": "$request_time", '
'"http_referer": "$http_referer", '
'"remote_user": "$remote_user" '
' }';
access_log logs/access.log log_json;
重启
# /usr/local/nginx/sbin/nginx -s reload
该博客介绍了如何在Linux环境中安装Nginx,包括安装依赖如gcc、pcre、zlib和openssl,然后编译并安装Nginx。接着,配置Nginx的日志格式为JSON,以便于数据分析。最后,展示了如何启动Nginx服务以及检查其运行状态,并通过访问服务器来生成访问日志。

被折叠的 条评论
为什么被折叠?



