nginx: update systemd unit using nginx recommendation
PATCH 1/2 nginx: update systemd unit using nginx recommendation
From: André Draszik <[email protected]>
Our systemd unit doesn't follow the official
recommendation, see
https://www.nginx.com/resources/wiki/start/topics/examples/systemd/
Most importantly:
* it should start after some additional specific targets/units
* using PrivateTmp is a useful security feature, in particular to avoid cross domain scripting via the temp folder
* using systemd's $MAINPID, we can distinguish between multiple running nginx instances correctly
--- meta-webserver/recipes-httpd/nginx/files/nginx.service | 10 +++++++--- meta-webserver/recipes-httpd/nginx/nginx.inc | 1 + 2 files changed, 8 insertions(+), 3 deletions(-)
meta-webserver/recipes-httpd/nginx/files/nginx.service +7 -3
@@ -1,11 +1,15 @@ [Unit] -Description=Nginx Server -After=network.target +Description=The NGINX HTTP and reverse proxy server +After=syslog.target network.target remote-fs.target nss-lookup.target + [Service] Type=forking PIDFile=/run/nginx/nginx.pid +ExecStartPre=@SBINDIR@/nginx -t ExecStart=@SBINDIR@/nginx -ExecStop=@SBINDIR@/nginx -s stop ExecReload=@SBINDIR@/nginx -s reload +ExecStop=@BINDIR@/kill -s QUIT $MAINPID +PrivateTmp=true + [Install] WantedBy=multi-user.target
meta-webserver/recipes-httpd/nginx/nginx.inc +1 -0
@@ -117,6 +117,7 @@ do_install () { sed -i -e 's,@SYSCONFDIR@,${sysconfdir},g' \ -e 's,@LOCALSTATEDIR@,${localstatedir},g' \ -e 's,@SBINDIR@,${sbindir},g' \ + -e 's,@BINDIR@,${bindir},g' \ ${D}${systemd_unitdir}/system/nginx.service fi }
Signature · 1 line
2.20.1
PATCH 2/2 nginx: configuration update
From: André Draszik <[email protected]>
Restructure the main configuration file to simplify custom configuration:
* support inclusion of configuration fragments from subdirectories:
- /etc/nginx/modules-enabled/*.conf
- /etc/nginx/conf.d/*.conf
- /etc/nginx/sites-enabled/*
* default site (port 80):
- move into /etc/nginx/sites-available/default_server
and enable via symlink in /etc/nginx/sites-enabled/
- listen on IPv6
- drop unneeded example fragments
* configure and enable gzip
* update TLS settings to drop SSLv3 and enable TLSv1.3 for some safer defaults
* update remaining bits to follow Debian standard configuration
https://salsa.debian.org/nginx-team/nginx/blob/62a54a8ba66ee6cc1b4f8a33dab9a6f27a3fdac4/debian/conf/nginx.conf
* drop unneeded example configuration bits from /etc/nginx/*.default
These changes, in particular the configuration fragment support allow to easily customise nginx based on individual requirements.
In addition, it is now possible for other recipes / packages to drop fragments into the respective directories in /etc/nginx without having to meddle with /etc/nginx/nginx.conf
--- .../nginx/files/default_server.site | 14 ++ .../recipes-httpd/nginx/files/nginx.conf | 139 +++++------------- meta-webserver/recipes-httpd/nginx/nginx.inc | 14 ++ 3 files changed, 62 insertions(+), 105 deletions(-) create mode 100644 meta-webserver/recipes-httpd/nginx/files/default_server.site
meta-webserver/recipes-httpd/nginx/files/default_server.site new file +14 -0
@@ -0,0 +1,14 @@ +# Default server configuration +server { + listen 80 default_server; + listen [::]:80 default_server; + + root /var/www/localhost/html; + + index index.html index.htm; + + server_name _; + + # redirect server error pages to the static page /50x.html + error_page 500 502 503 504 /50x.html; +}
meta-webserver/recipes-httpd/nginx/files/nginx.conf +34 -105
152 lines not on this page · raw message
meta-webserver/recipes-httpd/nginx/nginx.inc +14 -0
@@ -16,6 +16,7 @@ SRC_URI = " \ file://nginx-cross.patch \ file://0001-Allow-the-overriding-of-the-endianness-via-the-confi.patch \ file://nginx.conf \ + file://default_server.site \ file://nginx.init \ file://nginx-volatile.conf \ file://nginx.service \
@@ -102,15 +103,28 @@ do_install () { install -d ${D}${sysconfdir}/nginx install -m 0644 ${WORKDIR}/nginx.conf ${D}${sysconfdir}/nginx/nginx.conf + sed -i 's,/etc/,${sysconfdir}/,g' ${D}${sysconfdir}/nginx/nginx.conf sed -i 's,/var/,${localstatedir}/,g' ${D}${sysconfdir}/nginx/nginx.conf sed -i 's/^user.*/user ${NGINX_USER};/g' ${D}${sysconfdir}/nginx/nginx.conf + install -Dm 0644 ${WORKDIR}/default_server.site ${D}${sysconfdir}/nginx/sites-available/default_server + sed -i 's,/var/,${localstatedir}/,g' ${D}${sysconfdir}/nginx/sites-available/default_server install -d ${D}${sysconfdir}/nginx/sites-enabled + ln -s ../sites-available/default_server ${D}${sysconfdir}/nginx/sites-enabled/ install -d ${D}${sysconfdir}/default/volatiles install -m 0644 ${WORKDIR}/nginx-volatile.conf ${D}${sysconfdir}/default/volatiles/99_nginx sed -i 's,/var/,${localstatedir}/,g' ${D}${sysconfdir}/default/volatiles/99_nginx sed -i 's,@NGINX_USER@,${NGINX_USER},g' ${D}${sysconfdir}/default/volatiles/99_nginx + # cleanup configuration folder + rm ${D}${sysconfdir}/nginx/*.default + + # add additional configuration folders + install -d ${D}${sysconfdir}/nginx/modules-available + install -d ${D}${sysconfdir}/nginx/modules-enabled + install -d ${D}${sysconfdir}/nginx/server-conf.d + install -d ${D}${sysconfdir}/nginx/conf.d + if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)};then install -d ${D}${systemd_unitdir}/system install -m 0644 ${WORKDIR}/nginx.service ${D}${systemd_unitdir}/system/
Signature · 1 line
2.20.1