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,中文能正常顯示

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章