Is it possible to call external scripts and retrieve output using nginx?

1.6k Views Asked by At

My site has a search function at /search/. For every search request captured by nginx, I want to run a Python script and have nginx behave differently depending on the output of said script, whether it's the exit code or stdout. So something like this (pseudocode):

location ~* "/search/(.*)" {
    set redirect_request = call "/usr/bin/python /home/me/script.py $1";

    if ($redirect_request = 1) {
        rewrite ^ /page;
    }
}

Is anything like this possible at all with nginx?

1

There are 1 best solutions below

0
On

The general short answer, as far as I know, is no. I guess that it would be very difficult to find a way to keep Nginx non-blocking with such a general type of external call.

However, you can "script" Nginx with Lua. http://wiki.nginx.org/HttpLuaModule You'll find plenty of tutorials on the web, and dev time is quite short. There is a module dedicated to that, which follows nginx philosophy.