HI All,
请帮忙看下下面的问题,谢谢!
模块中发起子请求(/mysql_query?name=lisi), 通过upstream(proxy_pass)访问( location /mysql), 但是此时带过来的URL中问号被转义了(mysql%3Fname=lisi), 并且ngx.var.arg_name 和 ngx.var.args参数都为空,不知道怎么修改才能获得参数(ngx.var.arg_name)。
配置如下:
location /mysql_test{
client_body_in_single_buffer on;
sub_request_mysql test;
}
location /mysql { -->此处计划访问数据库的,通过uri传过来的参数构造SQL语句
content_by_lua '
ngx.header.content_type = "text/plain";
ngx.say("hello",ngx.var.request_uri,ngx.var.arg_name,ngx.var.args); --》此处参数arg_name, args都为空
';
}
location /mysql_query {
proxy_pass http://localhost/mysql;
}
root@iZ2ze3uk97m2bfv681kyx4Z:/usr/local/openresty/nginx/logs# curl -i -X POST -H "'Content-type':'application/json'" -d '{"name":"lisi"}' http://47.93.228.87:80/mysql_test
HTTP/1.1 200 OK
Server: openresty/1.13.6.1
Date: Sun, 06 May 2018 13:00:03 GMT
Content-Type: text/plain; charset=GBK
Content-Length: 30
Connection: keep-alive
hello/mysqlFname=lisinilnil
日志:
2018/05/06 20:57:45 [emerg] 19792#0: *1 extern_db_sub_req_post_handler: 200 while sending to client, client: 47.93.228.87, server: localhost, request: "POST /mysql_test HTTP/1.1", subrequest: "/mysql_query?name=lisi", upstream: "http://127.0.0.1:80/mysql%3Fname=lisi", host: "47.93.228.87"
2018/05/06 20:57:45 [emerg] 19792#0: *1 data: 30, hello/mysql%3Fname=lisinilnil
while sending to client, client: 47.93.228.87, server: localhost, request: "POST /mysql_test HTTP/1.1", subrequest: "/mysql_query?name=lisi", upstream: "http://127.0.0.1:80/mysql%3Fname=lisi", host: "47.93.228.87" --》%3F
2018/05/06 20:57:45 [emerg] 19792#0: *1 extern_db_request_post_handler: status[200] while sending to client, client: 47.93.228.87, server: localhost, request: "POST /mysql_test HTTP/1.1", host: "47.93.228.87"
2018/05/06 20:57:45 [emerg] 19792#0: *1 extern_db_request_post_handler: send header ret[0] while sending to client, client: 47.93.228.87, server: localhost, request: "POST /mysql_test HTTP/1.1", host: "47.93.228.87"
2018/05/06 20:57:45 [emerg] 19792#0: *1 extern_db_request_post_handler: send body ret[0] while sending to client, client: 47.93.228.87, server: localhost, request: "POST /mysql_test HTTP/1.1", host: "47.93.228.87"
PS:
第一次发问题邮件,不确定用中文是否合适.如果要求必须是英文的话,请提醒。