I have a html form I am getting the username & 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).
index.html:
<form action="/form_validate" method="POST">
<label for="username">Username</label>
<input id="username" name="username" size="16" type="text"/>
<label for="password">Password</label>
<input name="password" size="16" type="password"/>
</form>
nginx.conf snip:
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/;
}
}
My issue is:
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".
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 & other files.
What am I doing wrong here?