[alibaba/tengine]access log中 url带中文不能正常显示

2024-07-10 553 views
7

/api/group/%e4%bb%98 实际上url 是 /api/group/付 post参数带中文,同样不能正常显示。这个该怎么解决呢,网上查找了方案 添加参数 log_escape off; 依旧没有效果。

回答

5

user work; worker_processes auto; worker_cpu_affinity auto;

error_log /data/ngx_logs/error.log error; pid /data/ngx_logs/nginx.pid;

worker_rlimit_nofile 102400;

events { use epoll; worker_connections 65535; reuse_port on; }

http { include mime.types; default_type application/octet-stream;

log_format  main  '$http_host|$remote_addr|$remote_user|$time_local|$request|$request_body|$request_time|$status|$body_bytes_sent|$http_referer|$http_user_agent|$http_x_forwarded_for|'
                  '$upstream_addr|$upstream_status|$upstream_response_time';

log_format  www  '$http_host|$remote_addr|$remote_user|$time_local|$request|$request_body|$request_time|$status|$body_bytes_sent|$http_referer|$http_user_agent|$http_x_forwarded_for|'
                  '$upstream_addr|$upstream_status|$upstream_response_time';

log_format  api  '$http_host|$remote_addr|$remote_user|$time_local|$request|$request_body|$request_time|$status|$body_bytes_sent|$http_referer|$http_user_agent|$http_x_forwarded_for|'
                  '$upstream_addr|$upstream_status|$upstream_response_time';

log_escape off;

access_log  /data/ngx_logs/access.log main buffer=32k flush=30s;

sendfile        on;
tcp_nopush      on;
tcp_nodelay         on;
keepalive_timeout   65;
keepalive_requests  100000;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;

client_body_buffer_size     128k;
client_max_body_size        10m;
client_header_buffer_size   1k;
large_client_header_buffers 4 4k;
output_buffers              1 32k;
postpone_output             1460;

gzip                    on;
gzip_http_version       1.1;
gzip_buffers            256 64k;
gzip_comp_level         5;
gzip_min_length         1000;
gzip_proxied            expired no-cache no-store private auth;
gzip_types              application/x-javascript text/javascript application/json text/css;
gzip_disable            "MSIE 6";
gzip_vary               on;

proxy_buffers           64 4k;

include /data/ngx_conf/vhosts/*.conf;

}

4

配置上 log_escape off; , 是可以显示汉字的。 你的情况是因为 /api/group/%e4%bb%98 这个是浏览器帮你转码了, tengine收到的原始请求就是 /%e4%bb%98, 而不是/付。 你直接用 curl 试试, 日志就可以打印出来汉字了,比如 :

curl http://localhost/api/group/付 
2

非常感谢。