<div dir="ltr"><div><div><div>Hello, igorclark<br><br></div>Perhahs you can create a shell to launch nginx, and before that, ejecute a shell to assign a environment variable as a result of the execution of a program, or create (update) a file that is to be included from nginx config file when starting<br>
<br>Some ideas:<br><br><a href="http://nginx.2469901.n2.nabble.com/Want-to-access-UNIX-environment-variable-td7584005.html">http://nginx.2469901.n2.nabble.com/Want-to-access-UNIX-environment-variable-td7584005.html</a><br>
<a href="https://www.google.com/search?client=ubuntu&channel=fs&q=get+environment+variable+from+nginx&ie=utf-8&oe=utf-8">https://www.google.com/search?client=ubuntu&channel=fs&q=get+environment+variable+from+nginx&ie=utf-8&oe=utf-8</a><br>
<br></div>Greetings,<br><br></div>Oscar<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Sep 4, 2014 at 7:07 AM, igorclark <span dir="ltr"><<a href="mailto:nginx-forum@nginx.us" target="_blank">nginx-forum@nginx.us</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I want to read some remote values via HTTP into nginx config variables, just<br>
once at nginx startup / reload time, and pass them as fastcgi_params into<br>
PHP scripts. I control the remote system, so I'll know if it needs to<br>
re-read and can send a HUP to nginx. I don't need it to happen every request<br>
though, because the value won't change for long periods - but it will change<br>
sometimes, and I don't want to have push more config out to multiple nginx<br>
servers if I can avoid it.<br>
<br>
Is there a way to do this that doesn't create problems?<br>
<br>
Here's what I've tried so far.<br>
<br>
This first one doesn't work, because the "API [is] disabled in the context<br>
of set_by_lua*":<br>
<br>
    set_by_lua $config_variable "<br>
        local result = ngx.location.capture('<a href="http://url.to.fetch/" target="_blank">http://url.to.fetch/</a>')<br>
        return result<br>
    "<br>
<br>
(Same with ngx.socket.*)<br>
<br>
This next one works; it feels horrible to do this but if it was just once at<br>
start-up, it might be OK - but this executes for every incoming request<br>
(confirmed by using /bin/date as the 'command' and just hitting refresh):<br>
<br>
    set_by_lua $config_variable "<br>
        local command = "/usr/bin/curl <a href="http://url.to.fetch/" target="_blank">http://url.to.fetch/</a>"<br>
        local handle = io.popen(command)<br>
        local result = handle:read("*a")<br>
        handle:close()<br>
        return result<br>
    "<br>
<br>
Same for this one, it executes for every request:<br>
<br>
    perl_set $config_variable '<br>
        sub {<br>
            $var = `/bin/date`;<br>
            return $var;<br>
        }<br>
    '<br>
<br>
Is there a good way to do this, that only executes once, and doesn't have<br>
horrible shell interactions?<br>
<br>
Thanks very much for your help,<br>
Igor<br>
<br>
Posted at Nginx Forum: <a href="http://forum.nginx.org/read.php?2,253063,253063#msg-253063" target="_blank">http://forum.nginx.org/read.php?2,253063,253063#msg-253063</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Oscar Fernandez Sierra<br><a href="mailto:oscaretu@gmail.com">oscaretu@gmail.com</a>
</div></div>