From 5055b00806cb56821dba39abf503923ea3f41e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Sat, 18 Jan 2025 10:35:29 +0100 Subject: [PATCH] Lighttpd: Add socket support and documentation --- Dockerfile | 1 + README.md | 23 ++++++++++++++++++++++- runtime/etc/lighttpd/lighttpd.conf | 25 ++++++++++++++++++------- runtime/usr/local/bin/start-server | 6 +++++- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1ab49931..a1dc8d6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -137,6 +137,7 @@ ENV MS_DEBUGLEVEL=0 \ LIGHTTPD_PORT=8080 \ LIGHTTPD_FASTCGI_HOST=spawn-fcgi \ LIGHTTPD_FASTCGI_PORT=3000 \ + LIGHTTPD_FASTCGI_SOCKET='' \ LIGHTTPD_ACCESSLOG_FORMAT="%h %V %u %t \"%r\" %>s %b" CMD ["/usr/local/bin/start-server"] diff --git a/README.md b/README.md index 2ca44fd8..20cddb47 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Only tags for minor releases exist, not tag for bug fixes. If the container is run as root, apache listens on port `80`. If it is run as another user, it listens on port `8080`. -## Tunings +## Apache Tunings You can use the following environment variables (when starting the container) to tune it: @@ -29,6 +29,27 @@ to tune it: - `APACHE_LIMIT_REQUEST_LINE`: The maximum size of the HTTP request line in bytes (defaults to `8190`) +## Lighttpd + +You can also use lighttpd as the web server. + +The main benefit of that is to have only one running process per container, that's useful especially on Kubernetes. + +For that you need tow containers, one for the MapServer and `spawn-fcgi`, and one for `lighttpd`. + +The environment variable needed by mapserver should be on the `spawn-fcgi` container. + +The MapServer logs will be available on the 'lighttpd' container. + +Used environment variables: + +- `LIGHTTPD_CONF`: The lighttpd configuration file (defaults to `/etc/lighttpd/lighttpd.conf`) +- `LIGHTTPD_PORT`: The port lighttpd will listen on (defaults to `8080`) +- `LIGHTTPD_FASTCGI_HOST`: The host of the FastCGI server (`spawn-fcgi`, defaults to `spawn-fcgi`) +- `LIGHTTPD_FASTCGI_PORT`: The port of the FastCGI server (`spawn-fcgi`, defaults to `3000`) +- `LIGHTTPD_FASTCGI_SOCKET`: The socket of the FastCGI server (defaults to `''`) +- `LIGHTTPD_ACCESSLOG_FORMAT`: The format of the access log (defaults to `"%h %V %u %t \"%r\" %>s %b"`) + ## Running multiple Mapfiles This section is for if you would like to use more than one Mapfile, or use a Mapfile diff --git a/runtime/etc/lighttpd/lighttpd.conf b/runtime/etc/lighttpd/lighttpd.conf index 0c81199d..8f6f775e 100644 --- a/runtime/etc/lighttpd/lighttpd.conf +++ b/runtime/etc/lighttpd/lighttpd.conf @@ -7,12 +7,23 @@ server.errorlog = "/dev/fd/2" accesslog.format = env.LIGHTTPD_ACCESSLOG_FORMAT accesslog.filename = "/dev/fd/2" -fastcgi.server = ( "" => - ( +env.LIGHTTPD_FASTCGI_SOCKET == "" { + fastcgi.server = ( "" => ( - "host" => env.LIGHTTPD_FASTCGI_HOST, - "port" => env.LIGHTTPD_FASTCGI_PORT, - "check-local" => "disable", - ), + ( + "host" => env.LIGHTTPD_FASTCGI_HOST, + "port" => env.LIGHTTPD_FASTCGI_PORT, + "check-local" => "disable", + ), + ) ) -) +} else { + fastcgi.server = ( "" => + ( + ( + "socket" => env.LIGHTTPD_FASTCGI_SOCKET, + "check-local" => "disable", + ), + ) + ) +} diff --git a/runtime/usr/local/bin/start-server b/runtime/usr/local/bin/start-server index 2d148225..9ff41ed1 100755 --- a/runtime/usr/local/bin/start-server +++ b/runtime/usr/local/bin/start-server @@ -4,7 +4,11 @@ if [[ "${SERVER}" == spawn-fcgi ]]; then echo "Starting with spawn-fcgi" # Save the environment to be able to restore it in the FCGI daemon (used in /usr/local/bin/mapserv_wrapper) ${GET_ENV} | sed -e 's/.\+/export "\0"/' > /tmp/init_env - /usr/bin/spawn-fcgi -p "${LIGHTTPD_FASTCGI_PORT}" -n -- /usr/local/bin/mapserv_wrapper + if [[ "${LIGHTTPD_FASTCGI_SOCKET}" == "" ]]; then + exec /usr/bin/spawn-fcgi -p "${LIGHTTPD_FASTCGI_PORT}" -n -- /usr/local/bin/mapserv_wrapper + else + exec /usr/bin/spawn-fcgi -s "${LIGHTTPD_FASTCGI_SOCKET}" -n -- /usr/local/bin/mapserv_wrapper + fi else if [[ "${SERVER}" == lighttpd ]]; then echo "Starting lighttpd"