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:


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.


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 '
    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.

| improve this answer | |
  • 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! – Daniel Farrell Nov 6 '16 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.