sailorproject / sailor

A Lua MVC Web Framework.
MIT License
921 stars 125 forks source link

Sailor based APP as a FCGI server #87

Open xspager opened 8 years ago

xspager commented 8 years ago

I was talking with @Etiene about getting Sailor to be a FCGI server so we would the the follow benefits:

After doing some testing I was surprised that since Remy knows how to deal with CGILua, and CGILua knows FCGI since it uses WSAPI to abstract the web server, you only need to install the package wsapi-fcgi

There are two ways to run a FCGI server, you can use something like spawn-fcgi (it is made by the lighttpd project but works with any web server) that is available at least on Debian and Ubuntu or letting the webserver creaiting FGCI proccess on demand (and reusing them of course)

To install wsapi-fcgi you will need on Ubuntu/Debian to install the libfcgi-dev

As an example you could use Nginx with a config like https://gist.github.com/xspager/86aacbd44d8a9996c8e6 and start the fcgi server with $ spawn-fcgi -f /home/me/sailor_app/index.lua -p 9000 and also on the first line of index.lua you would put #!/usr/bin/env /home/me/.lua/52/bin/cgilua.fcgi or '#!/usr/bin/env cgilua.fcgi' it the script cgilua.fcgi is on the PATH

Documentation for how to FCGI in some web servers:

Feel free to ask me any questions or say this is a terrible IDEA :)

As a bonus this test script only requires cgilua, wsapi and wsapi-fcgi https://gist.github.com/xspager/7cf2284f927edb6c4cbf

felipedaragon commented 8 years ago

@xspager With Remy, the idea was supporting as much envinronments as possible, so I think this is a good idea. Another thing that is missing is support for the IIS web server (a new Remy extension could add this)

xspager commented 8 years ago

Maybe we can skip Remy and write a wsapi adapter for both Apache and IIS. What do you think?

xspager commented 8 years ago

Also, since no change is needed in code to get a Sailor App to speak FCGI what about including this information on the documentation? Anybody willing to do it?

Etiene commented 8 years ago

Maybe we can skip Remy and write a wsapi adapter for both Apache and IIS. What do you think?

Remember working with nginx / openresty is essential

Also, since no change is needed in code to get a Sailor App to speak FCGI what about including this information on the documentation? Anybody willing to do it?

I can do that :)

xspager commented 8 years ago

I forget to mention @ignacio 's wsapi-openresty, since I did't tried myself I'll and report back :)

felipedaragon commented 8 years ago

@xspager maybe you can switch for it. i would recommend making sure that it supports all the environments and platforms currently supported by Remy. another thing you will need to look at is adapting the Sailor code to use the WSAPI format instead of the mod_lua's request_rec way of doing things (since Remy simply emulates the request_rec structure).

ignacio commented 8 years ago

Hi! To support as many servers as Remy does, one should write wsapi adapters for Lighttpd and lwan. On the other hand, wsapi already supports IIS. It seems to me that making Sailor into a wsapi application would be a lot of work, with not much gain?