Skip to content

Commit edf46df

Browse files
authored
Merge pull request #1459 from camptocamp/lighttpd
Add support of lighttpd
2 parents e0f1833 + 8279d59 commit edf46df

File tree

10 files changed

+161
-25
lines changed

10 files changed

+161
-25
lines changed

.github/dpkg-versions.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ camptocamp/qgis-server:latest:
309309
ubuntu_24_04/libxxhash0: 0.8.2-2build1
310310
ubuntu_24_04/libzip4t64: 1.7.3-1.1ubuntu2
311311
ubuntu_24_04/libzstd1: 1.5.5+dfsg2-2build1.1
312+
ubuntu_24_04/lighttpd: 1.4.74-1ubuntu3
312313
ubuntu_24_04/login: 1:4.13+dfsg1-4ubuntu3.2
313314
ubuntu_24_04/logsave: 1.47.0-2.4~exp1ubuntu4.1
314315
ubuntu_24_04/mawk: 1.3.4.20240123-1build1
@@ -686,6 +687,7 @@ camptocamp/qgis-server:latest-debug:
686687
ubuntu_24_04/libxxhash0: 0.8.2-2build1
687688
ubuntu_24_04/libzip4t64: 1.7.3-1.1ubuntu2
688689
ubuntu_24_04/libzstd1: 1.5.5+dfsg2-2build1.1
690+
ubuntu_24_04/lighttpd: 1.4.74-1ubuntu3
689691
ubuntu_24_04/login: 1:4.13+dfsg1-4ubuntu3.2
690692
ubuntu_24_04/logsave: 1.47.0-2.4~exp1ubuntu4.1
691693
ubuntu_24_04/mawk: 1.3.4.20240123-1build1

Dockerfile

+11-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ FROM runner AS runner-server
174174

175175
RUN --mount=type=cache,target=/var/lib/apt/lists,id=apt-list \
176176
--mount=type=cache,target=/var/cache,id=var-cache,sharing=locked \
177-
DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends libfcgi
177+
DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends \
178+
apache2 libapache2-mod-fcgid libfcgi lighttpd spawn-fcgi
178179

179180
# Be able to install font as nonroot
180181
RUN chmod u+s /usr/bin/fc-cache \
@@ -188,7 +189,14 @@ ENV APACHE_CONFDIR=/etc/apache2 \
188189
APACHE_RUN_DIR=/tmp/apache2 \
189190
APACHE_PID_FILE=/tmp/apache2/apache2.pid \
190191
APACHE_LOCK_DIR=/var/lock/apache2 \
191-
APACHE_LOG_DIR=/var/log/apache2
192+
APACHE_LOG_DIR=/var/log/apache2 \
193+
SERVER=apache \
194+
LIGHTTPD_CONF=/etc/lighttpd/lighttpd.conf \
195+
LIGHTTPD_PORT=8080 \
196+
LIGHTTPD_FASTCGI_HOST=spawn-fcgi \
197+
LIGHTTPD_FASTCGI_PORT=3000 \
198+
LIGHTTPD_FASTCGI_SOCKET= \
199+
LIGHTTPD_ACCESSLOG_FORMAT="%h %V %u %t \"%r\" %>s %b"
192200

193201
RUN a2enmod fcgid headers status \
194202
&& a2dismod -f auth_basic authn_file authn_core authz_user autoindex dir \
@@ -236,6 +244,7 @@ RUN adduser www-data root \
236244

237245
RUN ldconfig
238246

247+
VOLUME /tmp
239248
WORKDIR /etc/qgisserver
240249
EXPOSE 8080
241250
CMD ["/usr/local/bin/start-server"]

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ docker run --detach --publish=8380:80 --volume=${PWD}/qgis:/etc/qgisserver campt
1313
With the previous command, you'll get to your server with this URL:
1414
http://localhost:8380/?MAP=/etc/qgisserver/project.qgz&SERVICE=WMS&REQUEST=GetCapabilities
1515

16-
## Tuning
16+
## Apache Tunings
1717

1818
You can use the following variables (`-e` option in `docker run`):
1919

@@ -35,6 +35,27 @@ You can use the following variables (`-e` option in `docker run`):
3535

3636
Fonts present in the `/etc/qgisserver/fonts` directory will be installed and thus usable by QGIS.
3737

38+
## Lighttpd
39+
40+
You can also use lighttpd as the web server.
41+
42+
The main benefit of that is to have only one running process per container, that's useful especially on Kubernetes.
43+
44+
For that you need tow containers, one for the MapServer and `spawn-fcgi`, and one for `lighttpd`.
45+
46+
The environment variable needed by mapserver should be on the `spawn-fcgi` container.
47+
48+
The MapServer logs will be available on the 'lighttpd' container.
49+
50+
Used environment variables:
51+
52+
- `LIGHTTPD_CONF`: The lighttpd configuration file (defaults to `/etc/lighttpd/lighttpd.conf`)
53+
- `LIGHTTPD_PORT`: The port lighttpd will listen on (defaults to `8080`)
54+
- `LIGHTTPD_FASTCGI_HOST`: The host of the FastCGI server (`spawn-fcgi`, defaults to `spawn-fcgi`)
55+
- `LIGHTTPD_FASTCGI_PORT`: The port of the FastCGI server (`spawn-fcgi`, defaults to `3000`)
56+
- `LIGHTTPD_FASTCGI_SOCKET`: The socket of the FastCGI server (defaults to `''`)
57+
- `LIGHTTPD_ACCESSLOG_FORMAT`: The format of the access log (defaults to `"%h %V %u %t \"%r\" %>s %b"`)
58+
3859
## Get a stack trace in case of segfault
3960

4061
To get a good stack trace you should use the `-debug` image.

acceptance_tests/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.13.1 as base-all
1+
FROM python:3.13.1 AS base-all
22
LABEL maintainer "info@camptocamp.org"
33

44
# Fail on error on pipe, see: https://github.com/hadolint/hadolint/wiki/DL4006.
@@ -17,7 +17,7 @@ ENV PATH=/venv/bin:$PATH
1717

1818
# Used to convert the locked packages by poetry to pip requirements format
1919
# We don't directly use `poetry install` because it force to use a virtual environment.
20-
FROM base-all as poetry
20+
FROM base-all AS poetry
2121

2222
# Install Poetry
2323
WORKDIR /tmp

acceptance_tests/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ def connection_landingpage():
5353
Fixture that returns a connection to a running batch container.
5454
"""
5555
return Connection("http://qgis-landingpage:8080/", "http://www.example.com/")
56+
57+
58+
@pytest.fixture
59+
def connection_lighttpd():
60+
"""
61+
Fixture that returns a connection to a running batch container.
62+
"""
63+
return Connection("http://qgis-lighttpd:8080/", "http://www.example.com/")

acceptance_tests/docker-compose.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,33 @@ services:
4444
- acceptance_config
4545
user: www-data
4646

47+
qgis-spawn-fcgi:
48+
image: camptocamp/qgis-server:${DOCKER_TAG}
49+
environment:
50+
SERVER: spawn-fcgi
51+
QGIS_SERVER_LOG_LEVEL: '0'
52+
QGIS_PROJECT_FILE: /etc/qgisserver/project.qgs
53+
read_only: true
54+
links:
55+
- db
56+
volumes:
57+
- cache:/var/cache/qgisserver
58+
volumes_from:
59+
- acceptance_config
60+
user: 12311:12311
61+
62+
qgis-lighttpd:
63+
image: camptocamp/qgis-server:${DOCKER_TAG}
64+
environment:
65+
SERVER: lighttpd
66+
LIGHTTPD_FASTCGI_HOST: qgis-spawn-fcgi
67+
read_only: true
68+
links:
69+
- db
70+
# ports:
71+
# - 8385:8080
72+
user: 12311:12311
73+
4774
db:
4875
image: camptocamp/postgres:17-postgis-3
4976
environment:

acceptance_tests/test_wms.py

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ def test_get_capabilities(connection):
1616
], ElementTree.dump(answer)
1717

1818

19+
def test_get_capabilities_lighttpd(connection_lighttpd):
20+
ns = "{http://www.opengis.net/wms}"
21+
answer = connection_lighttpd.get_xml(
22+
"?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0",
23+
cache_expected=CacheExpected.DONT_CARE,
24+
cors=False,
25+
)
26+
assert [e.text for e in answer.findall(f"{ns}Service/{ns}Title")] == ["test"], ElementTree.dump(answer)
27+
assert [e.text for e in answer.findall(f".//{ns}Layer/{ns}Name")] == [
28+
"test",
29+
"polygons",
30+
], ElementTree.dump(answer)
31+
32+
1933
def test_get_map(connection):
2034
answer = connection.get_raw(
2135
"?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=polygons&STYLES=&"

runtime/etc/lighttpd/gen-server

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash -e
2+
3+
if [[ "${LIGHTTPD_FASTCGI_SOCKET}" == "" ]]; then
4+
echo '
5+
fastcgi.server = ( "" =>
6+
(
7+
(
8+
"host" => env.LIGHTTPD_FASTCGI_HOST,
9+
"port" => env.LIGHTTPD_FASTCGI_PORT,
10+
"check-local" => "disable",
11+
),
12+
)
13+
)
14+
'
15+
else
16+
echo 'fastcgi.server = ( "" =>
17+
(
18+
(
19+
"socket" => env.LIGHTTPD_FASTCGI_SOCKET,
20+
"check-local" => "disable",
21+
),
22+
)
23+
)
24+
'
25+
fi

runtime/etc/lighttpd/lighttpd.conf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
server.modules = ( "mod_accesslog", "mod_auth", "mod_fastcgi" )
2+
3+
server.document-root = "/none"
4+
server.port = env.LIGHTTPD_PORT
5+
server.errorlog = "/dev/fd/2"
6+
7+
accesslog.format = env.LIGHTTPD_ACCESSLOG_FORMAT
8+
accesslog.filename = "/dev/fd/2"
9+
10+
include_shell "./gen-server"

runtime/usr/local/bin/start-server

+40-20
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,46 @@ if [ -e /etc/qgisserver/fonts/ ]; then
55
fc-cache --really-force --system-only
66
fi
77

8-
# save the environment to be able to restore it in the FCGI daemon (used
9-
# in /usr/local/bin/qgis_mapsev_wrapper) for the startup code.
10-
# shellcheck disable=SC2086
11-
${GET_ENV} ${FILTER_ENV} | sed -e 's/^\([^=]*\)=.*/PassEnv \1/' > /tmp/pass-env
12-
13-
# Save the list of variables to be passed along with the FCGI requests (used in
14-
# /etc/apache2/conf-enabled/qgis.conf).
15-
# shellcheck disable=SC2086
16-
${GET_ENV} ${FILTER_ENV} | sed -e 's/.\+/export "\0"/' > /tmp/init-env
17-
18-
if [ "${UID}" == 0 ]; then
19-
echo "Switching listen port to 80"
20-
cd /tmp
21-
sed -i -e 's/<VirtualHost \*:8080>/<VirtualHost *:80>/' /etc/apache2/sites-available/000-default.conf
22-
sed -i -e 's/Listen 8080$/Listen 80/' /etc/apache2/ports.conf
23-
fi
8+
if [[ "${SERVER}" == spawn-fcgi ]]; then
9+
echo "Starting with spawn-fcgi"
10+
# Save the environment to be able to restore it in the FCGI daemon (used in /usr/local/bin/qgis-mapserv-wrapper)
11+
# shellcheck disable=SC2086
12+
${GET_ENV} ${FILTER_ENV} | sed -e 's/.\+/export "\0"/' > /tmp/init-env
13+
if [[ "${LIGHTTPD_FASTCGI_SOCKET}" == "" ]]; then
14+
exec /usr/bin/spawn-fcgi -p "${LIGHTTPD_FASTCGI_PORT}" -n -- /usr/local/bin/qgis-mapserv-wrapper
15+
else
16+
exec /usr/bin/spawn-fcgi -s "${LIGHTTPD_FASTCGI_SOCKET}" -n -- /usr/local/bin/qgis-mapserv-wrapper
17+
fi
18+
else
19+
if [[ "${SERVER}" == lighttpd ]]; then
20+
echo "Starting lighttpd"
21+
lighttpd -tt -f "${LIGHTTPD_CONF}"
22+
exec /usr/sbin/lighttpd -D -f "${LIGHTTPD_CONF}"
23+
else
24+
echo "Starting with apache2"
25+
26+
# save the environment to be able to restore it in the FCGI daemon (used
27+
# in /usr/local/bin/qgis-mapserv-wrapper) for the startup code.
28+
# shellcheck disable=SC2086
29+
${GET_ENV} ${FILTER_ENV} | sed -e 's/^\([^=]*\)=.*/PassEnv \1/' > /tmp/pass-env
30+
31+
# Save the list of variables to be passed along with the FCGI requests (used in
32+
# /etc/apache2/conf-enabled/qgis.conf).
33+
# shellcheck disable=SC2086
34+
${GET_ENV} ${FILTER_ENV} | sed -e 's/.\+/export "\0"/' > /tmp/init-env
2435

25-
trap 'echo "caught a SIGTERM"; kill -TERM $PID2; wait $PID2; kill -TERM $PID1; wait $PID1' TERM
26-
trap '' WINCH
36+
if [[ "${UID}" == 0 ]]; then
37+
echo "Switching listen port to 80"
38+
cd /tmp
39+
sed -i -e 's/<VirtualHost \*:8080>/<VirtualHost *:80>/' /etc/apache2/sites-available/000-default.conf
40+
sed -i -e 's/Listen 8080$/Listen 80/' /etc/apache2/ports.conf
41+
fi
2742

28-
rm -f "${APACHE_PID_FILE}"
43+
trap 'echo "caught a SIGTERM"; kill -TERM $PID2; wait $PID2; kill -TERM $PID1; wait $PID1' TERM
44+
trap '' WINCH
2945

30-
exec apache2 -DFOREGROUND
46+
rm -f "${APACHE_PID_FILE}"
47+
48+
exec apache2 -DFOREGROUND
49+
fi
50+
fi

0 commit comments

Comments
 (0)