nginx lua variable assignment in return

nginx follows:

 location /proxy{
                default_type 'text/plain';
                lua_code_cache off;

                the SET $ AppID '' ; // rewrite from lua in 

                set_by_lua_file $ url ' /home/cq/share/xyx/nginx_example/nginx_server/lua/proxy.lua ' ;

                #echo " url = $ url " ; // assignment url derived from lua in 
                proxy_pass $ url;
 }


lua follows:

local = ngx. var .arg_a;
local b = ngx. var .arg_b;
local c = ngx.var.arg_c;

ngx.header.content_type="text/plain";
ngx.var.appid = a;//写入到外部参数里

local uri = "https://api.weixin.qq.com/sns/jscode2session?appid="..a.."&secret="..b.."&js_code="..c.."&grant_type=authorization_code";

return uri;

 


In turn, get nginx variables in the lua

http {
    include       mime.types;
    default_type  application/octet-stream;
    # Set the contents of the log is written here in order to see if I can get to the headers of the Access - Token, just to write this value to the log.
    log_format  main "$http_access_token";
    # Set the path to save the log and log template, see here do not understand it, take a look at knowledge nginx logs.
    access_log  logs/access.log  main;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen      80;
        server_name localhost;
        location / {
            root    html;
            index   index.html index.htm;
        }

        error_page  500 502 503 504  /50x.html;

        location /test {
            #content_by_lua_block in {} represents the code, all codes lua
            content_by_lua_block {
                # Ngx with ngx.say output. Var .http_access_token
                ngx.say ( " value pass over the front end of the Access-Token headers are: " , NGX. var .http_access_token)
            }
       }
   }
}

 

Guess you like

Origin www.cnblogs.com/littlehb/p/12297706.html