I have followed the instructions
here and compiled OpenResty from the bundled source on my Ubuntu 14.04 64 bit server. As expected the compiled package ends up at /usr/local/openresty/nginx/sbin. I then set up a symlink from /etc/rc2.d to /etc/init.d/nginx which contains the init.d startup script for OpenResty which I found
here. I then edited /usr/local/openresty/conf/nginx.conf with just one additional line
At /etc/site/ I created the file site.cfg which contains, amongst other things,
root /home/html;
location /api{
lua_need_request_body "on";
content_by_lua_block {
ngx.say("Hello World!");
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Having restarted the server I went back to /usr/bin/openresty/sbin and tried the following
./nginx -v, returns openresty/1.9.7.1
./nginx -V, shows amoungs other things
--add-module = ../ngx_lua-0.9.20
--add-module = ../ngx_lua_upstream-0.04
--with-ld-opt=W1,-rpath,/usr/local/openresty/luajit/lib
/usr/local/openresty/luajit/bin is present and correct and contains luajit, luajit-2.1.0-beta1
./nginx -T reports no issues and my site.cfg file appears to have been included in the configuration correctly. And yet....
I created two files in my /home/html/api folder:
- A simple text file, test.txt, containing the words "Bonjour le monde!"
- A simple PHP file, test.php, containing the code
<?php
echo "Bonjour le monde!";
?>
When I browse to api/test.txt the text that appears in my browser is Hello World! = the expected result since the content_by_lua_block instruction in site.cfg, above effectively replaces the content read from test.txt.
However, when I visit test.php the browser displays Bonjour le monde as opposed to Hello World!. For good measure I tried moving the
directive below the
diective but with precisely the same result. I suspect there is a gap in my understanding of just how thse lua directives are meant to be used in OpenResty. I hope that someone here will be able to explain.