Trying to get the wsapi-fcgi to work.

66 views
Skip to first unread message

George Petsagourakis

unread,
Nov 19, 2013, 2:04:51 AM11/19/13
to kepler-...@googlegroups.com
Using Lua 5.2 with wsapi 1.6-1 and wsapi-fcgi 1.6-1 installed via luarocks, I have the following nginx configuration:

server {
    listen       127.0.0.1:8080;
    server_name  localhost;

    location / {
        root   /home/petsagouris/code/wsapitest/;
        index  index.html index.htm run.lua;
    }
   
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # Lua WSAPI
    # taken from http://mascarenhas.github.io/2009/10/24/wsapi-nginx-fcgi.html
    location ~ ^(.+\.lua)(.*)$ {
      root html;
      fastcgi_pass 127.0.0.1:9100;
      fastcgi_index run.lua;
      fastcgi_split_path_info ^(.+\.lua)(.*)$;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }
}


The launcher script is this:

#!/usr/bin/env lua
# filename: run.lua

local fastcgi = require"wsapi.fastcgi"
local app = require"app"
fastcgi.run(app.run)


and the actual app is this one:

#!/usr/bin/env wsapi.cgi
local coroutine = require "coroutine"

local M= {}
_ENV = M

function run(wsapi_env)
  local headers = { ["Content-type"] = "text/html" }

  local function hello_text()
    coroutine.yield("<html><body>")
    coroutine.yield("<p>Hello Wsapi!</p>")
    coroutine.yield("<p>PATH_INFO: " .. wsapi_env.PATH_INFO .. "</p>")
    coroutine.yield("<p>SCRIPT_NAME: " .. wsapi_env.SCRIPT_NAME .. "</p>")
    coroutine.yield("</body></html>")
  end

  return 200, headers, coroutine.wrap(hello_text)
end

return M


Both of them are executable at the moment (do I just need the run.lua to be executable or I have to keep both like that?) and I can get the correct responses from the command line when I go for $ ./run.lua or $ ./app.lua

When I visit localhost:8080 I get a "502 Bad Gateway" response and the following log line:

2013/11/19 09:02:51 [error] 31359#0: *26 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9100", host: "localhost:8080"

I find it really weird that I can get the scripts to work properly via the command line but they don't work when hit from the server. Anyone that can help me out with this?

Ian McIntosh

unread,
Nov 19, 2013, 10:29:34 PM11/19/13
to kepler-...@googlegroups.com
Hi George,

I believe the problem isn't wsapi but your nginx config.

Try changing the root statement just below  " location ~ ^(.+\.lua)(.*)$ { "

from

root html;

to

root /home/petsagouris/code/wsapitest/;

Then restart nginx.

Cheers, Ian
--
You received this message because you are subscribed to the Google Groups "Kepler Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kepler-projec...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

George Petsagourakis

unread,
Nov 20, 2013, 12:21:52 AM11/20/13
to kepler-...@googlegroups.com, i...@kognix.com
Thanks for spotting that Ian It is now working as intended. Furthermore I was wrong to think that the role of the fcgi module that wsapi-fcgi uses is the fastcgi application that the server connects to. The solution was to use spawn-fcgi as the fastcgi process. I've found out -with a little digging- the line to use to invoke it.

I will be posting a complete answer on the matter as soon as I am confident enough of the result because at the moment, even after applying your fix, there are still errors.
Reply all
Reply to author
Forward
0 new messages