title: Can I modify inbuilt Nginx variable with Lua?
body: <p>the nginx log format is :</p>
  
  <pre><code>log_format  main  '$remote_addr [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for" "$cookie_logintoken"';
  </code></pre>
  
  <p>I set the log_by_lua_file </p>
  
  <pre><code>log_by_lua_file xxxxx/ngx_lua_waf/log.lua;
  </code></pre>
  
  <p>and log.lua content: </p>
  
  <pre><code>ngx.req.set_header("User-Agent", "this is testing User-Agent")
  ngx.req.set_header("Referer", "this is testing Referer")
  </code></pre>
  
  <p>and access.log change</p>
  
  <pre><code>127.0.0.1 [17/Dec/2016:16:21:47 +0800] "GET /test/client.php HTTP/1.1" 200 1370 "this is testing Referer" "this is testing User-Agent" "-" "-"
  </code></pre>
  
  <p>how can I change the nginx build-in var like $request ?   I want to change the 
  "GET /test/client.php HTTP/1.1" before nginx log to access.log</p>
  
  <p>ngx.var.request = "xxxx"  will be error :</p>
  
  <pre><code>failed to run log_by_lua*: xxxx/ngx_lua_waf/log.lua:15: variable "request" not changeable
  </code></pre>
  
  <p>but I dont konw how to change it with ngx.req.set_header </p>
  
  <p>can anyone tell me how to change it?</p>