How to add conf for my owner lua cgi on nginx+uwsgi web service?

Hi All,

At beginning, I already implemented some lua cgi and run it on uhttpd well.
I added lua_prefix at uhttpd.conf, like

# uhttpd.conf
list lua_prefix '/test =/usr/lib/lua/test/index.lua'

# cgi at /usr/lib/lua/test/
root@OpenWrt:/usr/lib/lua/test# ls
example.lua    index.lua   utils.lua

# request
# curl -v -k "https://127.0.0.1/test/example"
> GET /test/example HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.66.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Keep-Alive: timeout=20
< ETag: "44e-1-5f61bcdf"
< Last-Modified: Wed, 16 Sep 2020 07:21:03 GMT
< Date: Wed, 16 Sep 2020 07:23:54 GMT
< Content-Type: text/html
< Content-Length: 1
< 

Now, I want to porting this to ngnix+uwsgi web server.
I added some configs, like

# 
root@OpenWrt:~# cat /etc/uwsgi/vassals/luci-test_io.ini 
[uwsgi]
strict = true
if-not-env = UWSGI_EMPEROR_FD
socket = /var/run/luci-test_io.socket
chmod-socket = 666
cheap = true
end-if =
plugin = cgi
cgi-mode = true
cgi = /www
chdir = /usr/lib/lua/test/
buffer-size = 10000
reload-mercy = 8
max-requests = 2000
limit-as = 200
reload-on-as = 256
reload-on-rss = 192
no-orphans = true
post-buffering = 8192
socket-timeout = 120
thunder-lock = true
plugin = syslog
disable-logging = true
req-logger = syslog:uwsgi-luci-test_io
log-format=%(method) %(uri) => return %(status) (%(rsize) bytes in %(msecs) ms)
chmod-socket = 666
cgi-safe = /usr/libexec/cgi-io
cgi-dontresolve = true
cgi-close-stdin-on-eof = true
cheap = true
idle = 360


# add /test folder at /etc/nginx/luci_uwsgi.conf 
location /test/ {          
                index  index.lua;
                include uwsgi_params;
                uwsgi_param SERVER_ADDR $server_addr;
                uwsgi_modifier1 9;
                uwsgi_pass unix:////var/run/luci-test_io.socket;
}

When I do request /test/example, I always got Not Found.
Questions:

  1. Is it possible to run lua cgi on nginx+uwsgi web service and expect the behavior just same as uhttpd?
  2. If Q1 is no, is there an example to try?
  3. If Q1 is yes, which part is wrong?
    Please help. Thanks.

Hi All,

Anyone has experience can help? Thanks.

Hi all,

I would like to share what I already done on my device and it works. Thanks.

  1. Add location via unix domain socket
# /etc/nginx/luci_uwsgi.conf 
location /test {
    auth_digest 'OpenWrt';
    include uwsgi_params;
    uwsgi_param SERVER_ADDR \$server_addr;
    uwsgi_modifier1 9;
    uwsgi_pass unix:////var/run/luci-test.socket;
}

# /etc/uwsgi/vassals/luci-test.ini
[uwsgi]
strict = true
if-not-env = UWSGI_EMPEROR_FD
socket = /var/run/luci-test.socket
chmod-socket = 666
cheap = true
end-if =
plugin = cgi
cgi-mode = true
cgi = /www/
chdir = /usr/lib/lua/test/
buffer-size = 10000
reload-mercy = 8
max-requests = 2000
limit-as = 200
reload-on-as = 256
reload-on-rss = 192
enable-threads = true
post-buffering = 8192
socket-timeout = 120
thunder-lock = true
plugin = syslog
logger = luci syslog:uwsgi-luci
log-route = luci luci:
disable-logging = true
req-logger = syslog:uwsgi-luci
log-format=%(method) %(uri) => return %(status) (%(rsize) bytes in %(msecs) ms)
threads = 3
processes = 3
cheaper-algo = spare
cheaper = 1
cheaper-initial = 1
cheaper-step = 1
master = true
idle = 360
  1. Create a entry Lua script.
# /www/test 
#!/usr/bin/lua
--require "luci.cacheloader"
require "test.entry"
--luci.dispatcher.indexcache = "/tmp/luci-indexcache"
test.entry.run()
  1. Create Lua CGI
# /usr/lib/lua/test/entry.lua 
-- Copyright 2008 Steven Barth <steven@midlink.org>
-- Licensed to the public under the Apache License 2.0.

module("test.entry", package.seeall)
require("nixio.util")
require("luci.http")
require("luci.sys")
require("luci.dispatcher")

function run()
    print("State: 200 OK\n")
end

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