2

So I have a bash script that I want to execute/run on each "page load" of url so that it will modify (creating symlinks) to a /public/html/ folder that I want the server to then serve.

The problem is I figured out how to do one or the other not both.

I can show the directory with nginx root /public/html/ etc. or I can run the script by having instead of root /public/html/ having:

content_by_lua("/myscript.sh")';

But if I use content by lua, the script does run and create what I need inside /public/html but Nginx then just shows a blank screen. I want a way to then have nginx actually show the directory listing of /public/html after it runs the myscript.sh using content_by_lua.

I just started using nginx because of this task and am clueless how to do this, I did search around but its not an easy question to phrase for google or here.

1 Answer 1

3

Maybe I just figured it out? I added ngx.redirect("/"); So I have a / with location /public/html/ in my nginx.conf and also a:

    location /lua {
    default_type text/plain;
    content_by_lua '
    os.execute("/myscript.sh")
    return ngx.redirect("/")';

I would have preferred to just one 'location' instead of using redirect like that but at least I have something that seems to work. Improvements are welcome.

1
  • Yeah that makes sense. Your shell script never returned any content, hence the blank page. Send like a goofy way to do it ( run the script when the content changes, not on a user request) but I'm sure you're way beyond this now anyway. Cool example of inline Lua though!
    – erik258
    Nov 6, 2016 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .