网站开发课程总结,seo方法图片,最有效的100个营销方法,城市分类信息网站建设目录 安装
1.安装相关类库
2.安装编译openresty
3.编写配置启动openresty服务
4.通过 openresty 保存日志数据到系统 安装
1.安装相关类库
yum install -y readline-devel pcre-devel openssl-devel gcc
2.安装编译openresty
wget https://openresty.org/download/open…目录 安装
1.安装相关类库
2.安装编译openresty
3.编写配置启动openresty服务
4.通过 openresty 保存日志数据到系统 安装
1.安装相关类库
yum install -y readline-devel pcre-devel openssl-devel gcc
2.安装编译openresty
wget https://openresty.org/download/openresty-1.15.8.2.tar.gz
tar -zxvf openresty-1.15.8.2.tar.gz ./configure
make
make install
3.编写配置启动openresty服务
创建一个目录保存nginx.conf文件
这里我们在openresty创建目录目录名为 jast 在哪里创建都可以
mkdir jast
在jast目录下创建 conf 目录 与 logs目录
mkdir logs
mkdir conf
在conf目录下创建文件 nginx.conf 内容如下
worker_processes 1;
error_log logs/error.log;
events {worker_connections 1024;
}
http {server {listen 2199;location / {default_type text/html;content_by_lua ngx.say(pHello, World!/p);}}
}代表我们监控2199端口返回内容为Hello, World!
启动nginx服务
/usr/local/openresty/nginx/sbin/nginx -p /root/openresty/openresty-1.15.8.2/jast -c conf/nginx.conf-p 刚刚创建的jast目录项目目录
-c 刚刚创建的配置文件目录 查看服务
[root jast]# ps -ef|grep nginx
root 17576 1 0 11:12 ? 00:00:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx -p /root/openresty/openresty-1.15.8.2/jast -c conf/nginx.conf
nobody 17577 17576 0 11:12 ? 00:00:00 nginx: worker process通过浏览器访问http://ip:2199查看返回结果成功 4.通过 openresty 保存日志数据到系统
log.gif 方式
使用log.gif方便前端做埋点日志
修改nginx.conf 文件
# vim nginx.conf worker_processes 1;
error_log logs/error.log;
events {worker_connections 1024;
}
http {server {listen 2199;location / {default_type text/html;content_by_lua ngx.say(pHello, World!/p);}location /log.gif {#伪装成gif文件default_type image/gif;#本身关闭access_logaccess_log off;#使用lua将nginx的接收参数写入到日志文件中log_by_lua_file conf/log_conf.lua;#返回空图片empty_gif;}}
}编写log_conf.lua 文件
# vim log_conf.lua -- 引入lua json库
local cjson require cjson-- 获取请求参数
local request_args_tab ngx.req.get_uri_args()-- 获取系统时间
local time os.date(%Y%m%d%H,unixtime)-- 创建file对象注意这里目录是启动openresty时 -p 指定目录下的logs目录并且 logs 权限要设置为 chmod ox
local file io.open(logs/data- .. time .. .log,a)-- 创建json对象
local log_json {}-- 将请求参数转为json
for k,v in pairs(request_args_tab) dolog_json[k] v
end-- json数据写入文件并\n换行
file:write(cjson.encode(log_json),\n)file:flush()重新加载配置文件
/usr/local/openresty/nginx/sbin/nginx -p /root/openresty/openresty-1.15.8.2/jast -c conf/nginx.conf -s reload请求接口http://ip:2199/log.gif?test测试数据ab
查看logs目录下数据接收成功