diff --git a/Dockerfile b/Dockerfile index 1ab49931..3c72692e 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/gen-server b/runtime/etc/lighttpd/gen-server new file mode 100755 index 00000000..86202a83 --- /dev/null +++ b/runtime/etc/lighttpd/gen-server @@ -0,0 +1,25 @@ +#!/bin/bash -e + +if [[ "${LIGHTTPD_FASTCGI_SOCKET}" == "" ]]; then + echo ' +fastcgi.server = ( "" => + ( + ( + "host" => env.LIGHTTPD_FASTCGI_HOST, + "port" => env.LIGHTTPD_FASTCGI_PORT, + "check-local" => "disable", + ), + ) +) +' +else + echo 'fastcgi.server = ( "" => + ( + ( + "socket" => env.LIGHTTPD_FASTCGI_SOCKET, + "check-local" => "disable", + ), + ) +) +' +fi diff --git a/runtime/etc/lighttpd/lighttpd.conf b/runtime/etc/lighttpd/lighttpd.conf index 0c81199d..1044973a 100644 --- a/runtime/etc/lighttpd/lighttpd.conf +++ b/runtime/etc/lighttpd/lighttpd.conf @@ -7,12 +7,4 @@ server.errorlog = "/dev/fd/2" accesslog.format = env.LIGHTTPD_ACCESSLOG_FORMAT accesslog.filename = "/dev/fd/2" -fastcgi.server = ( "" => - ( - ( - "host" => env.LIGHTTPD_FASTCGI_HOST, - "port" => env.LIGHTTPD_FASTCGI_PORT, - "check-local" => "disable", - ), - ) -) +include_shell "bash ./gen-server" diff --git a/runtime/usr/local/bin/start-server b/runtime/usr/local/bin/start-server index 2d148225..2418e2c2 100755 --- a/runtime/usr/local/bin/start-server +++ b/runtime/usr/local/bin/start-server @@ -4,10 +4,15 @@ 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" + lighttpd -t -f "${LIGHTTPD_CONF}" exec lighttpd -D -f "${LIGHTTPD_CONF}" else echo "Starting with apache2"