OpenWrt Forum Archive

Topic: Help: uHttpd Lua Redirect

The content of this topic has been archived on 14 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I am new to Lua and I want to create a web app based on uhttpd and Lua : some static .html pages and few redirects.
But I don't want to install another web server, my question is:

How can I implement a custom redirect (302 http header) with Lua? With default configuration I created a lua dummy file in /www/cgi-bin/  (0755) and the output is:

Unable to launch the requested CGI program:
  /www/cgi-bin/1.lua: No such file or directory
root@OpenWrt:/#  uci show uhttpd
uhttpd.main=uhttpd
uhttpd.main.listen_http='0.0.0.0:88' '[::]:88'
uhttpd.main.listen_https='0.0.0.0:443' '[::]:443'
uhttpd.main.redirect_https='0'
uhttpd.main.home='/www'
uhttpd.main.rfc1918_filter='1'
uhttpd.main.max_requests='3'
uhttpd.main.max_connections='100'
uhttpd.main.cert='/etc/uhttpd.crt'
uhttpd.main.key='/etc/uhttpd.key'
uhttpd.main.cgi_prefix='/cgi-bin'
uhttpd.main.script_timeout='60'
uhttpd.main.network_timeout='30'
uhttpd.main.http_keepalive='20'
uhttpd.main.tcp_keepalive='1'
uhttpd.main.ubus_prefix='/ubus'
uhttpd.px5g=cert
uhttpd.px5g.days='730'
uhttpd.px5g.bits='1024'
uhttpd.px5g.country='ZZ'
uhttpd.px5g.state='Somewhere'
uhttpd.px5g.location='Uknown'
uhttpd.px5g.commonname='OpenWrt'
root@OpenWrt:/# cat www/cgi-bin/1.lua
#!/usr/bin/lua

function handle_request(env)
        local function main()
                        print("Content-Type: text/html")
                        print("")
                        print("<!DOCTYPE html>")
                        print("Hello World! ... wenn nicht.")
        end
        main()

endroot@OpenWrt:/#

Thank you for your attention!

There are many duplicates of this thread, I'm guessing you got that error message and thought your submission didn't get through. You can delete them by pressing the "Delete topic" button at the bottom right of each post.

Google the LUA documentation?

The discussion might have continued from here.