Hi Tomas,

> I would like to ask whether you ever deploy multiple picolisp
> applications on a server and if yes what is your setup (assuming the
> only http entrance from outside is the port 80)?

In fact, this is rather the normal case. There is hardly ever a server
running only a single application.


> I imagine that I could start several apps on different ports, put each
> behind httpGate and use a web server with url rewriting.

Right. Just that 'httpGate' already does "url rewriting", it is its main
purpose (besides to SSL de/encrytion).

You probably know the demo apps "rcsim.7fach.de" or "app.7fach.de". At
some times there were more than 60 applications running on that machine.
If you connect, say, to "rcsim.7fach.de", you'll see the address being
remapped to "http://7fach.de/18100";.

'httpGate' detects such URLs, and connects to "localhost" on port 18100.
This has the advantage that these ports can even be blocked by a
firewall to the outside world.


> Is there a way of achieving similar thing without a "heavy-weight"
> server with url rewriting?

I try to describe the way we are doing it. We used several slightly
different approaches in the past, depending on the situation. I'll boil
it down to a simple example.


Here is "home.l":

################################################################
# 26sep08abu
# (c) Software Lab. Alexander Burger

# *DNS *Dom

(allowed ()
   "@home" "favicon.ico" )

(load "lib/http.l")

(de main ()
   (setq *DNS
      (mapcar
         '((Dom)
            (let Dns (list (split (chop Dom) ".") NIL)
               (in (list "bin/balance" "-sort" (pack "dns/" Dom))
                  (while (name (read))
                     (idx (cdr Dns) @ T)
                     (set @ (pack Dom '/ (read))) ) )
               Dns ) )
         (dir "dns/") ) ) )

(de go ()
   (server 65500 "@home") )

(de home @
   (out NIL
      (prinl
         (align 2 (caddr (date (date)))) " " (tim$ (time T))
         " [" *Adr "] " *Host " (" *Agent ")" ) )
   (setq *Dom (split (mapcar lowc *Host) "."))
   (while (cdddr *Dom)
      (pop '*Dom) )  # Discard "www." etc.
   (and
      (assoc (cdr *Dom) *DNS)
      (idx (cdr @) (pack (car *Dom)))
      (redirect *Gate "://" (val (car @))) ) )

# vi:et:ts=3:sw=3
################################################################


It uses a directory "dns/", containing files, each with the name of a
domains pointing to that server, e.g. "7fach.de", "7fach.info" or
"7fach.com".

An example of "dns/7fach.de" would be:

################################################################
# 26sep08abu

"app"       "8080"
"test"      "8080/opt/start.l"

"svb"       "14700"
"simple"    "18000"
"rcsim"     "18100"
################################################################

So "8080" or "14700" are the ports where the individual applications are
listening on.


The 'mapcar' in the 'main' function in "home.l" builds an assoc-list of
domain names and 'idx' indexes, and stores it in the global '*DNS'. The
keys in those indexes are the application names ("sub"-domains), and the
values of those names (= transient symbols) are the actual URL's to map
to. For example, the value of "app" will be "7fach.de/8080", while that
of "test" is "7fach.de/8080/opt/start.l".


As "home.l" is listening on port 65500 (see the function 'go'),
'httpGate' was started twice (as root) with 65500 as the default port:

   # cd /home/app
   # bin/httpGate 80 65500
   # bin/httpGate 443 65500 pem/7fach


The 'home' application is started the normal way, like all other
applications:

   $ ./p home.l lib/app.l -main -go -wait >>log/home 2>&1 &


Now, whenever a HTTP request arrives on port 80 or 443, the 'home'
function will print a log message, reduce URLs like "www.app.7fach.de"
to "app.7fach.de", lookup the local URL, and redirect the request to
that application. Note that from now on the application does handle all
subsequent requests by itself, 'home' is only involved for the initial
call.

I hope I didn't forget anything. Please ask if so.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]

Reply via email to