Hi everyone,
I'm new to the group (and to nginx and lua in general..), so apologies if I'm asking something that has already been asked (couldn't find it) or really dumb :).
I've implemented some logic in nginx with lua that will redirect the user based on whether or not he has a specific cookie:
- If the user has a specific cookie: it will get redirected to another domain (using `ngx.redirect` directive).
- If the user doesn't have a specific cookie: I would like to assign a new cookie to the request (using `ngx.req.set_header()` directive) and directly pass the request to a uwsgi application through a socket using `lua`.
Because of the nature of the steps that occur before, I know the cookie will persist in the user's browser, I just want to avoid another trip back to the user's browser for the cookie to be set. I'm not sure what the best approach to pass the request to the uwsgi application through a socket would be. In nginx I think something like this will work:
```
location / {
proxy_set_header X-Forwarded-For $remote_addr;
add_header P3P 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"';
uwsgi_pass unix:///var/run/my_app/uwsgi.sock;
include uwsgi_params;
uwsgi_modifier1 8;
uwsgi_modifier2 1;
}````
but I would like to change this into:
```
location / {
rewrite_by_lua_block {
require("lua_logic_script").run()
}
}
````
where `lua_logic_script` has been loaded outside the `location` and the `server` blocks but inside the `http` block. All the logic would be lua's responsibility and so if the logic changes in the future, the nginx configuration doesn't need to be touched, just the lua implementation.
Thanks a lot in advance!
Eddie