This is an example or template of a website powered by Hunchentoot web server. It was used for www.chalaev.com in the past, but as of 2022 www.chalaev.com is powered by the website builder.
This project was my first step to understand how one can use Common Lisp to run a real-life web server. My (closed-source) website builder grew out of this code.
www.chalaev.com is my old personal website which I am using to test Hunchentoot. This project is about server (back end) code; the front end code serves mostly for demonstration purposes.
The following server features are used in www.chalaev.com:
- serve static files and generated pages on GET request,
- basic authentication,
- customized error pages (e.g. 404.html),
- serves
index.html
when asked for/
, andpage.html
when asked forpage
(requires hunchentoot update).
Usual linux
environment, sbcl
, quicklisp
, emacs
.
Two sbcl
packages unavailable in quicklisp
: cl-simple-logger and lisp goodies, unpacked into your local quicklisp
repository:
tar xjf cl-shalaev.tbz --directory=$HOME/quicklisp/local-projects/
tar xjf simple-log.tbz --directory=$HOME/quicklisp/local-projects/
where it is assumed that your quicklisp
is installed in ~/quicklisp/
.
Compiling is unnecessary: we could just launch sbcl
on the server and evaluate
(ql:quickload :web-server)
(web-server:start t)
However, I prefer to compile because compilation
- makes the code faster,
- saves valuable system resources on the server: e.g., we do not need to install
sbcl
there, and - makes it more difficult for
Forces of Darknesssystem administrators to analyze back end code on the server.
www.chalaev.com is hosted on a (US-based) VPS server for $2/month; for this price one enjoys 512Mb of RAM and 10Gb of disk space which might be enough for small business usage if system resources are used carefully.
make
compiles the code to a 16Mb binary file which is copied to the server and launched there.
(Manual SBCL compilation with --with-sb-core-compression
is required to shrink the binary size.)
You probably have to update Makefile configuration
(specifying where your sbcl
and quicklisp
are installed)
to make it work on your system.
Apart from code from this project we also need
Configuring certbot
and nginx
is discussed elsewhere;
The specific configuration file responsible for www.chalaev.com
resides in /etc/nginx/sites-enabled/chalaev.com
Swank allows to connect to the (remote) code and update it (or change variables' values) without actually restarting the server. Since we do not want to open 4210th port on the server, let us tunnel it to the 4015th one on the local host:
ssh -o ControlMaster=auto -o ControlPath=/tmp/chalaev.%C -L 4015:localhost:4210 -fN chalaev.com
ssh -o ControlMaster=auto -o ControlPath=/tmp/chalaev.%C -O check chalaev.com
(You might want to update your ~/.ssh/config file to improve connection reliability.)
Then in local emacs
we
M-x slime-connect
localhost
4015
After that, we just use slime for debugging, just as for locally running code, but feeling almost like debugging the Deep Space 1 spacecraft ☺.
This code is released under MIT license.