Nginx + Tora + Haxe

The ultimate combination for Web Apps

This is a quick overview of what you can do with Tora applications. For those of you who don’t know what Tora is, Nicolas made a good post about it here: .

Until recently Tora had to run behind Apache which unfortunately made it eat up a fair bit of memory with those big blocking Apache processes. The main points of Tora are to reduce memory usage and speed up start up time of a query, so it’s not exactly a good fit to be running behind 10MB-each Apache processes that are mostly idling. Now sure you could configure Apache to use a worker MPM instead of the default prefork, but tbh it’s a lot of headaches. Nginx was built from the ground up to be a reverse proxy so that’s what we should be using.

Thanks to we have FastCGI implemented with Tora now so we can communicate with Nginx. The setup is dead simple.

  1. Get the latest version of Tora . I’ve also backported this to Haxe 2.10/Neko 1.8 at .
  2. Build it and put tora.n somewhere.
  3. Run “neko tora -fcgi” to run the tora binary. -fcgi sets it to FastCGI mode.
  4. Next I’m going to assume you have Nginx set up. If you don’t know how there are a ton of articles to do this. FastCGI reverse proxying works right out of the box. So all you need to do is add this to your config:
location / {
fastcgi_pass localhost:6666;
fastcgi_param SCRIPT_FILENAME $document_root/index.n;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING q=$uri&$query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

Note: This is assuming you are doing the standard rewrite of to, but feel free to make adjustments!

And there you have it. Tora running behind Nginx.

Since Haxe also compiles to JavaScript and has out of the box support for general purpose servers, you can also quite easily build the client and the push server in Haxe as well.

All in all this makes Haxe a blazingly fast alternative to the standard NodeJS deployment for a single language across the entire web stack.

Co-founder and CTO of — making unique gaming experiences. Cryptocurrency enthusiast.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store