Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Nginx authentication and dynamic proxy

$
0
0
Hi,

I have setup a nginx server (openresty). I need to have authentication based on post params (user, pass, code) and get the result from auth query to redirect on intranet server (proxy_pass http://$address:$port;).

My problem is:

- get variable from post data
- save session-like auth token (for launch only one time the auth query)

Proto configuration:

location / {
set $address '';
access_by_lua '
local mysql = require "resty.mysql"
local db, err = mysql:new()
local ok, err, errno, sqlstate = db:connect{
host = "127.0.0.1",
port = 3306,
database = "database",
user = "user",
password = "password",
}
res, err, errno, sqlstate = db:query("select * from services where username = " .. username .. " and password = " .. password .. " and code = " .. code) -- username, password and code is from POST DATA
ngx.var.address = res[1].hostname .. ":" .. res[1].port
';
proxy_pass http://$address;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Many thanks for response.

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>