title: nginx lua processing form data
body: <p>I have a html form I am getting the username &amp; password and I wanted to pass it on to a web server which require a basic authentication. This is a very minimalistic web server with nginx/lua support only (no php/perl/python).</p>
  
  <p>index.html:</p>
  
  <pre><code>&lt;form action="/form_validate" method="POST"&gt;
  &lt;label for="username"&gt;Username&lt;/label&gt;
  &lt;input id="username" name="username" size="16" type="text"/&gt;
  &lt;label for="password"&gt;Password&lt;/label&gt;
  &lt;input name="password" size="16" type="password"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>nginx.conf snip:</p>
  
  <pre><code> upstream web_svr 
    {
      least_conn;
      server 127.0.0.1:8080;
    }
  
  
    server
    {
      listen       80;
      server_name  testSvr;
  
      location / 
      {
        root /var/html;
        index index.html;
      }
  
      location /form_validate/
      {
        set_form_input $username username;
        set_form_input $password password;
  
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Authorization "Basic $digest";
        proxy_redirect off;
  
        log_by_lua '
          ngx.header.content_type = ("text/plain")
          ngx.log(ngx.ERR,"username: (",ngx.var.username,")")
          ngx.log(ngx.ERR,"password: (",ngx.var.password,")")
        ';
        proxy_pass http://web_svr/;
      }
    }
  </code></pre>
  
  <p>My issue is:</p>
  
  <p>In the form,  if I define the "form action=/form_validate" the form data does not processed. Nginx side see this request as a "GET" method rather than a "POSt".</p>
  
  <p>But, if I do define it as "form action=/form_validate/", the form data does get processed, but unfortunately my proxy_pass call get messed up. When it hits the proxied server, it does not know the path to all the java script, CSS &amp; other files.</p>
  
  <p>What am I doing wrong here?</p>