simple lua file publising

27 views
Skip to first unread message

ramakanth varala

unread,
Aug 22, 2022, 1:24:28 AM8/22/22
to openresty-en
Hi All,

I am beginner with nginx/openresty.

want to use lua files with openresty 1-21.4.1

I have a simple hello.lua file as shown below.

#!/usr/bin/lua

print ("Content-type: test/plain\n\n")
print ("hello World")

my nginx.conf is as below 

user  labuser;
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            #root   html;
            #index  index.html index.htm;
            default_type text/plain;
            }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

syntax is coming as ok
but when I try to access this file like localhost/hello.lua , its printing all the file contents
instead of the just printing helloworld.

Any steps I am missing here.

Thanks

Rainer Canavan

unread,
Aug 22, 2022, 8:47:37 AM8/22/22
to openre...@googlegroups.com
On Mon, Aug 22, 2022 at 7:24 AM ramakanth varala
<ramakant...@gmail.com> wrote:
>
> Hi All,
>
> I am beginner with nginx/openresty.
>
> want to use lua files with openresty 1-21.4.1
>
> I have a simple hello.lua file as shown below.
>
> #!/usr/bin/lua
[...]

that's not how openresty is usually used. See the content_by_lua
examples regarding "dynamic dispatch" in
https://github.com/openresty/lua-nginx-module/blob/master/README.markdown
how to achieve something similar to what you want to do. Note the
"CAUTION" in the comment there and make absolutely sure you don't
allow any "../" or other means to escape your intended path. Also,
reconsider if you can get away with only a finite number of lua files
that are explicitly configured in (or inlined e.g. in
content_by_lua_block inside) your nginx.conf.

Rainer

Nelson, Erik - 2

unread,
Aug 22, 2022, 9:27:32 AM8/22/22
to openre...@googlegroups.com
ramakanth varala Sent Monday, August 22, 2022 1:24 AM

> I am beginner with nginx/openresty.
> want to use lua files with openresty 1-21.4.1
> I have a simple hello.lua file as shown below.

I find the 'getting started' link pretty useful

https://openresty.org/en/getting-started.html

----------------------------------------------------------------------
This message, and any attachments, is for the intended recipient(s) only, may contain information that is privileged, confidential and/or proprietary and subject to important terms and conditions available at http://www.bankofamerica.com/emaildisclaimer. If you are not the intended recipient, please delete this message.
Reply all
Reply to author
Forward
0 new messages