PicoLisp behind nginx proxy

The simplest setup with PicoLisp server which does not use the usual PicoLisp HTML based GUI framework can be achieved using a simple nginx proxy:

server {
  listen       80;
  server_name  example.logand.com;
  access_log   Web/example.logand.com-access.log;
  error_log    Web/example.logand.com-error.log;
  location / {
    proxy_set_header  Host $host;
    proxy_set_header  Gate "$scheme $remote_addr";
    proxy_pass        http://127.0.0.1:1234;
  }
}

Such setup is especially convenient if you control URLs yourselves using rewriteUrl and do not rely on the default PicoLisp URL conventions.

If you take advantage of the PicoLisp HTML based GUI with per process sessions, then you can avoid httpGate (the default PicoLisp proxy) and also implement a fallback for expired sessions as follows:

location ~ ^/[0-9]+ {
  if ($request_filename ~* /([0-9]+)/?(.*)) {
    set $gate       http://127.0.0.1:$1/$2$is_args$args;
  }
  proxy_set_header  Host $host;
  proxy_set_header  Gate "$scheme $remote_addr";
  proxy_pass        $gate;
  error_page        502 = /fallback$uri;
}
location ~ ^/fallback/[0-9]+ {
  internal;
  proxy_set_header  Host $host;
  proxy_set_header  Gate "$scheme $remote_addr";
  proxy_pass        http://127.0.0.1:65001;
}

Start your application on the fallback port (here 65001) and any new session URL will go to the right port/process (same as with httpGate). If the session expires and the session process terminates, the fallback will get the user back to the initial (usually login) screen of the main application process on the default port. Note that at the moment, nginx proxy supports HTTP 1.0 only and always closes the connections for each request.

It is possible to add more location handlers in the nginx configuration and, for example, separate static content served directly by nginx from dynamic content served by your PicoLisp server:

location / {
  root       Web/example.logand.com;
  index      index.html index.htm;
  autoindex  on;
}

This way it is possible to take advantage of standard tools for processing web logs, optimise serving of static content and make user’s experience a bit more pleasant.

2009-07-22

Next:
Up: Blog
Home: logand.com