OpenResty up and running but...

151 views
Skip to first unread message

Atul

unread,
Jan 13, 2016, 11:01:54 AM1/13/16
to openresty-en
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

include /etc/site/*;

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:

  1. A simple text file, test.txt, containing the words "Bonjour le monde!"
  2. 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 


location
/api {
...
}
 directive below the 


location
~ \.php$




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.

Robert Paprocki

unread,
Jan 13, 2016, 12:21:46 PM1/13/16
to openre...@googlegroups.com
This is a result of how nginx is handing the request, based on multiple location {} blocks. You have two separate location blocks, but only one of them has a content_by_lua directive. When the client requests a file ending in .php, the 'location ~ \.php$' block is used, which does not have a content_by_lua filter. If you wanted the content filter to apply to -all- locations, you could move the content_by_lua directive to the server {} block, instead of the /api location {} block.

See also http://nginx.org/en/docs/http/ngx_http_core_module.html#location for some detail on how location directives are processed.

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages