Can not set uhttpd to run a custom LUA cgi script

I want to direct an URL of the webserver to a custom LUA cgi script. Here is the current configuration:

config uhttpd 'main'
        list listen_http ''
        list listen_http '[::]:80'
        list listen_https ''
        list listen_https '[::]:443'
        option redirect_https '0'
        option home '/www'
        option rfc1918_filter '1'
        option max_requests '3'
        option max_connections '100'
        option cert '/etc/uhttpd.crt'
        option key '/etc/uhttpd.key'
        option script_timeout '60'
        option network_timeout '30'
        option http_keepalive '20'
        option tcp_keepalive '1'
        option ubus_prefix '/ubus'
        option cgi_prefix '/cgi-bin'
        option lua_prefix '/cgi-bin/luci=/usr/lib/lua/luci/sgi/uhttpd.lua /test=/www/test/lua/test.lua'

config cert 'defaults'
        option days '730'
        option key_type 'ec'
        option bits '2048'
        option ec_curve 'P-256'
        option country 'ZZ'
        option state 'Somewhere'
        option location 'Unknown'
        option commonname 'OpenWrt'

And the hello world script (/www/test/lua/test.lua):

function handle_request(env)
        uhttpd.send("Status: 200 OK\r\n")
        uhttpd.send("Content-Type: text/plain\r\n\r\n")
        uhttpd.send("Hello world.\n")

But when I go to the browser I always get a 404:


Also I have noticed that the LUCI's main page "/cgi-bin/luci/" still working also when I remove

uci del uhttpd.main.cgi_prefix

uci del uhttpd.main.lua_prefix

I find this weird and I do not understand why.

Any clue with this?


Option lua_prefix only becomes effective when uhttpd-mod-lua is installed, otherwise the option is ignored and normal path resolving / CGI handling is performed.

Removing option cgi_prefix has no effect because uhttpd's implicit default is /cgi-bin as well.

1 Like

Thanks, I will try this.

Solved. Thanks a lot!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.