nginx log 中文

os: centos_6.3
nginx: 1.8.1

通过curl -d "哈哈" localhost/viewlog发送请求后,查看log发现中文不能正常显示,被转为了16进制字符

img

春哥一语中的,遂下载patch,重新编译nginx。因为nginx1.8.1爆出了漏洞,需要打上官方补丁。需要篡改nginx版本号,可修改src/core/nginx.h

编译nginx需准备如下第三方包,在git或者各自官网上下载:

1. lib-1.2.8
2. pcre-8.39
3. lua-nginx-module-0.9.20
4. nginx-upload-module-2.2.0(git clone -b 2.2 https://github.com/vkholodkov/nginx-upload-module)
5. ngx_devel_kit-0.2.19
6. Nginx-1.8.1
7. openssl-1.0.1t

# wget http://nginx.org/download/patch.2016.write2.txt
# wget https://raw.github.com/agentzh/ngx_openresty/master/patches/nginx-1.2.7-log_escape_non_ascii.patch
# tar cvf nginx.1.8.1.tar.gz
# cd nginx.1.8.1
# patch -p1 < ../nginx-1.2.7-log_escape_non_ascii.patch
# patch -p0 < ../patch.2016.write2.txt
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.1t --add-module=../nginx-upload-module --add-module=../ngx_devel_kit-0.2.19 --add-module=../lua-nginx-module-0.9.7
# make

编译过程中出现如下错误:

./configure: error: ngx_http_lua_module requires the Lua library.

原因为缺少luajit库,解决方法:

wget http://luajit.org/download/LuaJIT-2.0.3.tar.gz
tar xvfz LuaJIT-2.0.3.tar.gz
make && make install

或者:

yum install lua-devel -y

将编译的好nginx可执行文件(objs/nginx)替换掉原来的,重新加载nginx.
再次使用 curl -d "哈哈" localhost/viewlog
观察log,中文能正常显示

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值