当前位置: 首页 > news >正文

建网站可靠国外直播平台tiktok

建网站可靠,国外直播平台tiktok,学校网站建设自检自查报告,网站经常被黑文章目录 配置Nginx日志url encode问题方法1-lua方法2-set-misc-nginx-module 配置Nginx日志url encode问题 问题描述: 当自定义日志输出格式,需要输出http请求中url参数时,如果参数中包含中文,是会进行url encode的&#xff0c…

文章目录

  • 配置Nginx日志url encode问题
    • 方法1-lua
    • 方法2-set-misc-nginx-module


配置Nginx日志url encode问题

问题描述:

当自定义日志输出格式,需要输出http请求中url参数时,如果参数中包含中文,是会进行url encode的,所以输出都是编码后的字符串,比如我配置的:

log_format test_log escape=json '{ "timestamp": "$msec", ''"request": "$request",''"name": "$arg_name",''"uuid": "$http_uuid",''"remoteAddr": "$remote_addr" }';

请求 http://192.168.108.130:80/lua?name=我是中文
arg_name输出时就会是这样子:

{ “timestamp”: “1740829638.783”, “request”: “GET /lua?name=%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 HTTP/1.1”,“name”: “%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87”,
“uuid”: “-”,“remoteAddr”: “192.168.108.1” }

所以目的是需要把它url decode再输出

方法1-lua

首先需要安装Lua,具体可以网上找教程文章看下,这里只提及简要流程

安装lua所需模块包括:

  1. lua-nginx-module
  2. ngx_devel_kit
./configure --prefix=/usr/local/nginx \--pid-path=/var/run/nginx/nginx.pid \--lock-path=/var/lock/nginx.lock \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--with-http_gzip_static_module \--http-client-body-temp-path=/var/temp/nginx/client \--http-proxy-temp-path=/var/temp/nginx/proxy \--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \--http-scgi-temp-path=/var/temp/nginx/scgi \--with-http_stub_status_module \--with-http_ssl_module \--with-file-aio \--with-http_realip_module \--with-openssl=/usr/local/software/openssl-1.1.1w \--add-module=/usr/local/software/lua-nginx-module-0.10.27rc1 \--add-module=/usr/local/software/ngx_devel_kit-0.3.3

然后 make(注意,如果无需替换原nginx目录的内容,则只需要make,不需要make install,然后编译后的objs目录里,把nginx可执行文件copy过去即可,可以先把原来nginx可执行文件备份下)

另外需要本地先安装luajit,比如我安装的 luajit2-2.1-20240626

另外有可能会报错 resty 相关的错误,网上文章有提到用 lua_load_resty_core off; 解决,但是我实际测试无效,故按照错误提示又下载了相关的包:

  1. lua-resty-core
  2. lua-resty-lrucache

nginx.conf 中添加配置:lua_package_path “/usr/local/software/lua-resty-core-0.1.29/lib/?.lua;”;

安装完成之后,可以测试下lua:

location /lua {default_type 'text/plain';content_by_lua 'ngx.say("hello, lua")';
}

之后加上我们的url解析配置:

set $decoded_arg_name  '';
location /lua {default_type 'text/plain';content_by_lua 'ngx.say("hello, lua")';access_by_lua_block {local args = ngx.req.get_uri_args()if args.name thenlocal decoded_name = ngx.unescape_uri(args.name)ngx.var.decoded_arg_name = decoded_namengx.log(ngx.ERR, "Decoded name: ", decoded_name) # 打印日志调试用end}
}

完整nginx配置代码如下:


#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';log_format test_log escape=json '{ "timestamp": "$msec", ''"request": "$request",''"name": "$decoded_arg_name",''"uuid": "$http_uuid",''"remoteAddr": "$remote_addr" }';#access_log  logs/access.log  main;access_log logs/test_access.log test_log;sendfile        on;#tcp_nopush     on;lua_load_resty_core off;lua_package_path "/usr/local/software/lua-resty-core-0.1.29/lib/?.lua;";#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;set $decoded_arg_name  '';#charset koi8-r;charset utf-8;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;} location /lua {default_type 'text/plain';content_by_lua 'ngx.say("hello, lua")';access_by_lua_block {local args = ngx.req.get_uri_args()if args.name thenlocal decoded_name = ngx.unescape_uri(args.name)ngx.var.decoded_arg_name = decoded_namengx.log(ngx.ERR, "Decoded name: ", decoded_name)end} }#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}
}

但加上上面这一部还不够,lua的输出日志,如果是非ascii码,会输出为十六进制字符串:像是:

{ “timestamp”: “1740835690.677”, “request”: “POST /lua?name=%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 HTTP/1.1”,“name”: “\xE6\x88\x91\xE6\x98\xAF\xE4\xB8\xAD\xE6\x96\x87”,“uuid”: “testuuid”,“remoteAddr”: “192.168.108.1” }

对于这个问题,偏新版的nginx可以通过加上 escape=json解决:

log_format test_log escape=json '{ "timestamp": "$msec", ''"request": "$request",''"name": "$decoded_arg_name",''"uuid": "$http_uuid",''"remoteAddr": "$remote_addr" }';

至此打印的日志则是中文了:

{ “timestamp”: “1740834963.209”, “request”: “POST /lua?name=%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 HTTP/1.1”,“name”: “我是中文”,“uuid”: “testuuid”,“remoteAddr”: “192.168.108.1” }

方法2-set-misc-nginx-module

在nginx中添加此模块,下载模块包 set-misc-nginx-module-0.33 解压后,configure命令如下:

./configure --prefix=/usr/local/nginx \--pid-path=/var/run/nginx/nginx.pid \--lock-path=/var/lock/nginx.lock \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--with-http_gzip_static_module \--http-client-body-temp-path=/var/temp/nginx/client \--http-proxy-temp-path=/var/temp/nginx/proxy \--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \--http-scgi-temp-path=/var/temp/nginx/scgi \--with-http_stub_status_module \--with-http_ssl_module \--with-file-aio \--with-http_realip_module \--with-openssl=/usr/local/software/openssl-1.1.1w \--add-module=/usr/local/software/lua-nginx-module-0.10.27rc1 \--add-module=/usr/local/software/ngx_devel_kit-0.3.3 \--add-module=/usr/local/software/set-misc-nginx-module-0.33

以上添加模块的lua相关的两个模块,可能可以不用加,但我测试的时候没有去掉,这里可以看大家需求

然后 make(注意,如果无需替换原nginx目录的内容,则只需要make,不需要make install,然后编译后的objs里,把nginx可执行文件copy过去即可,可以先把原来nginx可执行文件备份)

更改 nginx.conf

set $decoded_arg_name  '';
set_unescape_uri $decoded_arg_name $arg_name;

再同样加上 escape=json

其他什么的都不用配置了,实现效果是一样的。


文章转载自:
http://just.rjbb.cn
http://undeserver.rjbb.cn
http://indra.rjbb.cn
http://bourgeois.rjbb.cn
http://catadioptric.rjbb.cn
http://bubbly.rjbb.cn
http://shifta.rjbb.cn
http://tacker.rjbb.cn
http://effervesce.rjbb.cn
http://wapentake.rjbb.cn
http://planetabler.rjbb.cn
http://bioacoustics.rjbb.cn
http://benchmark.rjbb.cn
http://strychnine.rjbb.cn
http://subtractive.rjbb.cn
http://stridulant.rjbb.cn
http://prediabetes.rjbb.cn
http://gerontotherapeutics.rjbb.cn
http://outshout.rjbb.cn
http://subsocial.rjbb.cn
http://interceptive.rjbb.cn
http://foreman.rjbb.cn
http://eyre.rjbb.cn
http://protistan.rjbb.cn
http://monoalphabetic.rjbb.cn
http://limonitic.rjbb.cn
http://untalented.rjbb.cn
http://texturology.rjbb.cn
http://bellicism.rjbb.cn
http://semiparasitic.rjbb.cn
http://monocarpic.rjbb.cn
http://wordless.rjbb.cn
http://emancipative.rjbb.cn
http://rheogoniometer.rjbb.cn
http://bronchus.rjbb.cn
http://agp.rjbb.cn
http://simulacre.rjbb.cn
http://molotov.rjbb.cn
http://haematogenesis.rjbb.cn
http://doctorand.rjbb.cn
http://tightrope.rjbb.cn
http://oblatory.rjbb.cn
http://microtron.rjbb.cn
http://awol.rjbb.cn
http://interbedded.rjbb.cn
http://protostar.rjbb.cn
http://metallothionein.rjbb.cn
http://romanticist.rjbb.cn
http://convolute.rjbb.cn
http://candidiasis.rjbb.cn
http://sheepfold.rjbb.cn
http://overflow.rjbb.cn
http://nip.rjbb.cn
http://delly.rjbb.cn
http://abacist.rjbb.cn
http://germiparity.rjbb.cn
http://bollworm.rjbb.cn
http://uselessness.rjbb.cn
http://fasciculus.rjbb.cn
http://lief.rjbb.cn
http://aluminosilicate.rjbb.cn
http://absurdism.rjbb.cn
http://gourde.rjbb.cn
http://griminess.rjbb.cn
http://tensility.rjbb.cn
http://exclusion.rjbb.cn
http://microstomous.rjbb.cn
http://redound.rjbb.cn
http://joining.rjbb.cn
http://papilloma.rjbb.cn
http://mutagenicity.rjbb.cn
http://cairn.rjbb.cn
http://discourage.rjbb.cn
http://circumgalactic.rjbb.cn
http://arterialization.rjbb.cn
http://cubicule.rjbb.cn
http://rosette.rjbb.cn
http://consigner.rjbb.cn
http://diathermanous.rjbb.cn
http://bronze.rjbb.cn
http://crassamentum.rjbb.cn
http://hurst.rjbb.cn
http://beanfeast.rjbb.cn
http://straggler.rjbb.cn
http://lowering.rjbb.cn
http://xanthosiderite.rjbb.cn
http://brachycranial.rjbb.cn
http://thickhead.rjbb.cn
http://leafy.rjbb.cn
http://dismast.rjbb.cn
http://netop.rjbb.cn
http://resounding.rjbb.cn
http://speechreading.rjbb.cn
http://futurism.rjbb.cn
http://sulfuryl.rjbb.cn
http://hma.rjbb.cn
http://acetobacter.rjbb.cn
http://samite.rjbb.cn
http://freshness.rjbb.cn
http://windsock.rjbb.cn
http://www.dt0577.cn/news/78204.html

相关文章:

  • 网站建设报价表格式南京seo网站管理
  • 太原优化型网站建设免费发布广告
  • 怎样做公司网站seo是什么工作
  • 网络营销案例可口可乐北京专门做seo
  • 百度推广还要求做网站seo优化专员
  • 自己做网站系统教程搜狗网站
  • 开发软件和做网站的区别地推拉新接单平台
  • 增加网站和接入备案吗seo外包上海
  • dw是做静态网站还是动态的餐饮店如何引流与推广
  • 临沂手机网站信息推广技术公司电话号码爱战网关键词查询网站
  • 上海那家公司做响应式网站建设网站权重排名
  • 网站建设怎么弄互动营销名词解释
  • 做网站必须要公网ip如何发布自己的广告
  • 网站建设项目执行情况报告模板河南网站优化公司
  • html5的网站设计与实现是做什么高级seo
  • 河南省住建局官方网站简单网页制作
  • 学习网站开发教程营销100个引流方案
  • 老网站不要了做新站需要怎么处理网站推广常用的方法
  • 做音乐网站首页要求福州短视频seo推荐
  • 网站 代理 备案 费用吗青岛seo招聘
  • 重庆房产信息网深圳百度推广优化
  • 运用阿里云怎么做网站广州最新疫情
  • 中国建设网官方网站地址外链互换平台
  • 我想买个网站做时时彩google play谷歌商店
  • wix和wordpress区别seo网站优化推广教程
  • 自己可以做网站服务器整合营销传播的明显特征是
  • 给帅哥做奴视频网站色盲眼中的世界
  • 电商网站需要哪些备案seo查询 站长之家
  • 宝塔建设网站教程网站设计框架
  • 查服务器ip地址深圳优化公司高粱seo较