nginx将日志存入oracle,nginx将POST数据写到日志里
NGINX 是一个强大的web服务器,可以很容易的应对高负载的HTTP流量。nginx每处理一个连接,就会记录一条日志信息,包括诸如:IP地址,回复内容大小、http状态码等信息。
某种情况下,需要了解请求内容是什么,特别 POST 请求。 NGINX 默认只支持记录GET请求,对于记录POST请求需要使用额外的模块,例如, Echo module, 这个模块提供很多有用的指令: echo, time, and sleep。
记录POST请求我们需要使用到其中的 echo_read_request_body 命令和 $request_body 变量。
源码编译nginx增加echo模块步骤:
1.下载nginx和echo模块的源码:
curl -L -O 'https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz'
tar -xzvf v0.61.tar.gz && rm -f v0.61.tar.gz
mv echo-nginx-module-0.61 /tmp/echo-nginx-module
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxvf openssl-1.1.1g.tar.gz && openssl-1.1.1g.tar.gz
mv openssl-1.1.1g /tmp/openssl-1.1.1g
curl -O 'http://nginx.org/download/nginx-1.18.0.tar.gz'
tar -xzvf nginx-1.18.0.tar.gz && rm -f nginx-1.18.0.tar.gz
1
2
3
4
5
6
7
8curl-L-O'https://github.com/openresty/echo-nginx-module/archive/v0.61.tar.gz'
tar-xzvfv0.61.tar.gz&&rm-fv0.61.tar.gz
mvecho-nginx-module-0.61/tmp/echo-nginx-module
wgethttps://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar-zxvfopenssl-1.1.1g.tar.gz&&openssl-1.1.1g.tar.gz
mvopenssl-1.1.1g/tmp/openssl-1.1.1g
curl-O'http://nginx.org/download/nginx-1.18.0.tar.gz'
tar-xzvfnginx-1.18.0.tar.gz&&rm-fnginx-1.18.0.tar.gz
2.创建 nginx 用户, 用来运行nginx进程:
groupadd nginx
useradd -g nginx nginx
1
2groupaddnginx
useradd-gnginxnginx
3.从源码编译安装nginx:
cd nginx-1.18.0/ && ./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--with-file-aio \
--with-http_realip_module \
--with-openssl=/tmp/openssl-1.1.1g \
--add-module=/tmp/echo-nginx-module
make -j2
make install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15cdnginx-1.18.0/&&./configure\
--user=nginx\
--group=nginx\
--prefix=/usr/local/nginx\
--with-http_gzip_static_module\
--with-http_stub_status_module\
--with-http_ssl_module\
--with-pcre\
--with-file-aio\
--with-http_realip_module\
--with-openssl=/tmp/openssl-1.1.1g\
--add-module=/tmp/echo-nginx-module
make-j2
makeinstall
现在,nginx已安装完成,可以启动了。启动之前我们需要修改nginx的默认配置文件 /usr/local/nginx/conf/nginx.conf 来记录 HTTP request body 到日志文件。
NGINX 使用 access_log 指令记录多种 HTTP 请求相关的信息,哪些信息会或不会被记录则通过 log_format 指令来设置。Echo 模块通过调用 echo_read_request_body 方法存储 request body 到 request_body 变量中。为了记录 POST 请求体需要在配置文件中修改这些指令:
http {
...
log_format custom '$request_body';
access_log logs/access.log custom;
...
server {
location / {
echo_read_request_body;
...
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12http{
...
log_formatcustom'$request_body';
access_loglogs/access.logcustom;
...
server{
location/{
echo_read_request_body;
...
}
}
}
如果你的系统负载很高,你可以通过提高Linux打开文件数参数的大小来提高 NGINX 的处理能力。通过如下指令增加配置到文件末尾或直接修改相应的配置文件。
echo "fs.file-max = 1073741824" >> /etc/sysctl.conf
echo "nginx soft nofile 40960" >> /etc/security/limits.conf
echo "nginx hard nofile 81920" >> /etc/security/limits.conf
1
2
3echo"fs.file-max = 1073741824">>/etc/sysctl.conf
echo"nginx soft nofile 40960">>/etc/security/limits.conf
echo"nginx hard nofile 81920">>/etc/security/limits.conf
终于可以启动nginx并记录POST的请求内容了,运行nginx命令:
/usr/local/nginx/sbin/nginx
1/usr/local/nginx/sbin/nginx
测试
修改配置文件增加上面提到的三个配置。
[root@67 nginx]# cd /usr/local/nginx/conf/
[root@67 conf]# vi nginx.conf
测试并重新加载配置文件
[root@67 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@67 conf]# /usr/local/nginx/sbin/nginx -s reload
不带post参数会记录一个短横
[root@67 conf]# curl 127.0.0.1
[root@67 conf]# curl 127.0.0.1
[root@67 conf]# cd ../logs/
[root@67 logs]# tail -f access.log
-
-
[root@67 logs]# curl -d "site=redis.com.cn" 127.0.0.1
[root@67 logs]# tail -f access.log
-
-
site=redis.com.cn
排错
1.
checking for getaddrinfo() ... found
configuring additional modules
adding module in /tmp/echo-nginx-module
/tmp/echo-nginx-module/config: line 41: [: !=: unary operator expected
+ ngx_http_echo_module was configured
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.
缺少PCRE、ZLIB参考nginx安装教程先安装对应的源码包
2.
checking for OpenSSL library ... not found
checking for OpenSSL library in /usr/local/ ... not found
checking for OpenSSL library in /usr/pkg/ ... not found
checking for OpenSSL library in /opt/local/ ... not found
需要下载opensll包,参考nginx安装
cd /tmp
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxvf openssl-1.1.1g.tar.gz
--with-openssl=/tmp/openssl-1.1.1g
总结,本文主要介绍了如果配置nginx的日志记录功能,以及如何编译、安装、和使用echo模块。
参考:developers.redhat.com/blog/2016/05/23/configuring-nginx-to-log-post-data-on-linux-rhel/
nginx将日志存入oracle,nginx将POST数据写到日志里相关推荐
- Oracle 11g如何清理数据库的历史日志详解
11g清理数据库历史日志的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍 1. 创建存放数据库待删除日志文件路径 用于存放准备删除,这里假设放在/home/Oracle/del ...
- 使用 Nginx 转发 内网 Oracle 端口
一.基础环境 操作系统:Microsoft Windows Server 2019 datacenter (64位) Nginx 版本:nginx/1.21.4 数据库版本:Oracle ...
- Nginx —— nginx的命令行控制(nginx的启动与停止、重载配置文件、回滚日志文件、平滑升级等操作)
在linux中,需要使用命令来控制Nginx服务器的启动与停止.重载配置文件.回滚日志文件.平滑升级等行为. 默认情况下,nginx被安装在目录/usr/local/nginx中,其二进制文件路径为/ ...
- 12.10 Nginx访问日志 12.11 Nginx日志切割 12.12 静态文件不记录日志和过期时间
- 12.10 Nginx访问日志 - 12.11 Nginx日志切割 - 12.12 静态文件不记录日志和过期时间# 12.10 Nginx访问日志 - 日志的格式- vim /usr/local/ ...
- nginx整合php+lua+oracle环境搭建
nginx整合php+lua+oracle环境搭建 标签: nginxluaoraclephplinux 2014-09-25 10:39 1473人阅读 评论(0) 收藏 举报 分类: 技术( ...
- Nginx配置中的log_format用法梳理(设置详细的日志格式)
Nginx配置中的log_format用法梳理(设置详细的日志格式) nginx服务器日志相关指令主要有两条:一条是log_format,用来设置日志格式:另外一条是access_log,用来指定日志 ...
- RuoYi-Cloud 部署篇_01(windows环境 Oracle+nginx版本)
请参考以下二篇博文: RuoYi-Cloud 部署篇_01(windows环境 mysql版本) RuoYi-Cloud 部署篇_01(linux环境 oracle+nginx版本
- RuoYi-Cloud 部署篇_02(linux环境 Oracle +nginx版本)
文章目录 一.模块配置修改 1. ruoyi-gateway-dev.yml 2. ruoyi-auth-dev.yml 3. ruoyi-system-dev.yml 4. ruoyi-gen-de ...
- 宝塔修改Nginx服务器类型,宝塔面板nginx更改日志格式的方法
宝塔默认的日志格式比较简单,可能有些站长需要自定义日志格式,而不知道从何下手,其实这个就是简单的定义nginx的过程 只是宝塔的nginx配置文件存放位置与一般nginx不一样 宝塔存放nginx配置 ...
- Nginx默认虚拟主机、 Nginx用户认证、Nginx域名重定向、访问日志·····
2019独角兽企业重金招聘Python工程师标准>>> Ngninx默认虚拟主机 1.vim /usr/local/nginx/conf/nginx.conf //增加 2.incl ...
最新文章
- Windows 10预览版14316开启Bash命令支持
- (C++)1002 A+B for Polynomials
- mysql半备份_MySQL半同步复制与增强半同步复制详解及安装
- 【小米校招笔试】假如已知有n个人和m对好友关系(存于数字r)。如果两个人是直接或间接的好友(好友的好友的好友...),则认为他们属于同一个朋友圈,请写程序求出这n个人里一共有多少个朋友圈。
- 计算机科学考试题目,附录A 计算机科学与技术学科综合考试人工智能真题
- Unity3D性能优化
- 页面布局让footer居页面底部_网站页面结构与关键词布局技巧
- Three.js - 加载 .OBJ 格式模型(十六)
- 在Excel里快速插入目录
- 利用百度地图服务发布自己制作图片的地图
- Android接入三方登录——QQ、微信、Facebook、Twitter
- java问卷导入excel_Java利用已有的Excel文件导出新的Excel
- C++ 学习(四)程序流程结构 - 顺序结构、选择结构、循环结构、跳转语句
- 利用Python画一只小猪佩奇
- Laravel的中大型项目构架
- Ubuntu20.04部署ntp服务
- linux nohup的使用及详解
- 基于Skeleton的手势识别:SAM-SLR-v2
- 中南大学计算机学院教师名录,教师列表-中南大学商学院
- lillietest 正态分布的拟合优度测试
热门文章
- Object类的wait和notify详解
- 超赞!UX写手必备技能
- 是否采用SD-WAN?你需要先考虑以下问题
- Caused by: java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.HibernateTemplate
- 从Ibatis过渡到Mybatis-比较Mybaits较与Ibatis有哪些方面的改进
- 中国网站备案制度——祸国殃民
- Tomcat的设置3——设置虚拟主机
- SQL Server如何清除连接过的服务器名称历史?
- 内存管理-基础知识框架和关键结构体(一)
- java自学经历分享