Conditional $uri and html from file

Joel Parker at
Wed Nov 8 02:31:15 UTC 2017

I am using lua to parse out the username of the posted form and if the
username == user and password == password.

I want to change the URI to

otherwise, I want it just to do:

proxy_pass http://$http_host$uri$is_args$args;

The unauthorized.html is located in /data/www/ on the nginx server.

Here is my nginx.conf:

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

gzip on;

server {

listen 80;

location / {


lua_need_request_body on;

content_by_lua_block {


        local post_params = ngx.req.get_post_args();

        local username;

        local password;

        if (post_params) then

            -- Iterate through post params

            for key,value in pairs(post_params) do

                if (key == "username") then

                    username = value;

                elseif (key == "password") then

                    password = value;


                -- ngx.say(key," : ", value);


            if (username and password) then

                -- ngx.say(username);

-- ngx.say(password);

if (username == "user" and password =="password") then

      *-- WHAT DO I DO HERE ?*





proxy_pass http://$http_host$uri$is_args$args;



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list