blob: 260f5f320cffa1ea0f31987c3d5b09e015d6091e [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001SUMMARY = "HTTP and reverse proxy server"
2
3DESCRIPTION = "Nginx is a web server and a reverse proxy server for \
4HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high \
5concurrency, performance and low memory usage."
6
7HOMEPAGE = "http://nginx.org/"
8LICENSE = "BSD-2-Clause"
9
10SECTION = "net"
11
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012DEPENDS = "libpcre zlib"
Patrick Williamsb48b7b42016-08-17 15:04:38 -050013
14SRC_URI = " \
Patrick Williamsddad1a12017-02-23 20:36:32 -060015 http://nginx.org/download/nginx-${PV}.tar.gz \
16 file://nginx-cross.patch \
Brad Bishop316dfdd2018-06-25 12:45:53 -040017 file://0001-Allow-the-overriding-of-the-endianness-via-the-confi.patch \
Patrick Williamsddad1a12017-02-23 20:36:32 -060018 file://nginx.conf \
Brad Bishop19323692019-04-05 15:28:33 -040019 file://default_server.site \
20 file://proxy_params \
Patrick Williamsddad1a12017-02-23 20:36:32 -060021 file://nginx.init \
22 file://nginx-volatile.conf \
23 file://nginx.service \
Andrew Geissler82c905d2020-04-13 13:39:40 -050024 file://nginx-fix-pidfile.patch \
Patrick Williamsb48b7b42016-08-17 15:04:38 -050025"
26
Brad Bishop316dfdd2018-06-25 12:45:53 -040027inherit siteinfo update-rc.d useradd systemd
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028
Patrick Williams213cb262021-08-07 19:21:33 -050029SYSTEMD_SERVICE:${PN} = "nginx.service"
Patrick Williamsb48b7b42016-08-17 15:04:38 -050030
Patrick Williams213cb262021-08-07 19:21:33 -050031CFLAGS:append = " -fPIE -pie"
32CXXFLAGS:append = " -fPIE -pie"
Patrick Williamsb48b7b42016-08-17 15:04:38 -050033
34NGINX_WWWDIR ?= "${localstatedir}/www/localhost"
35NGINX_USER ?= "www"
36
37EXTRA_OECONF = ""
38DISABLE_STATIC = ""
39
Patrick Williams2390b1b2022-11-03 13:47:49 -050040PACKAGECONFIG ??= "ssl ${@bb.utils.filter('DISTRO_FEATURES', 'ipv6', d)}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080041
Andrew Geissler9aee5002022-03-30 16:27:02 +000042PACKAGECONFIG[gunzip] = "--with-http_gunzip_module,,"
Patrick Williamsddad1a12017-02-23 20:36:32 -060043PACKAGECONFIG[http2] = "--with-http_v2_module,,"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080044PACKAGECONFIG[ssl] = "--with-http_ssl_module,,openssl"
Brad Bishop15ae2502019-06-18 21:44:24 -040045PACKAGECONFIG[http-auth-request] = "--with-http_auth_request_module,,"
Patrick Williams2390b1b2022-11-03 13:47:49 -050046PACKAGECONFIG[ipv6] = "--with-ipv6,,"
Patrick Williamsddad1a12017-02-23 20:36:32 -060047
Patrick Williamsb48b7b42016-08-17 15:04:38 -050048do_configure () {
Patrick Williamsddad1a12017-02-23 20:36:32 -060049 if [ "${SITEINFO_BITS}" = "64" ]; then
50 PTRSIZE=8
51 else
52 PTRSIZE=4
53 fi
Patrick Williamsb48b7b42016-08-17 15:04:38 -050054
Patrick Williamsddad1a12017-02-23 20:36:32 -060055 echo $CFLAGS
56 echo $LDFLAGS
Patrick Williamsb48b7b42016-08-17 15:04:38 -050057
Patrick Williamsddad1a12017-02-23 20:36:32 -060058 # Add the LDFLAGS to the main nginx link to avoid issues with missing GNU_HASH
59 echo "MAIN_LINK=\"\${MAIN_LINK} ${LDFLAGS}\"" >> auto/cc/conf
60
61 ./configure \
62 --crossbuild=Linux:${TUNE_ARCH} \
Brad Bishop316dfdd2018-06-25 12:45:53 -040063 --with-endian=${@oe.utils.conditional('SITEINFO_ENDIANNESS', 'le', 'little', 'big', d)} \
Patrick Williamsddad1a12017-02-23 20:36:32 -060064 --with-int=4 \
65 --with-long=${PTRSIZE} \
66 --with-long-long=8 \
67 --with-ptr-size=${PTRSIZE} \
68 --with-sig-atomic-t=${PTRSIZE} \
69 --with-size-t=${PTRSIZE} \
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050070 --with-off-t=8 \
Patrick Williamsddad1a12017-02-23 20:36:32 -060071 --with-time-t=${PTRSIZE} \
72 --with-sys-nerr=132 \
73 --conf-path=${sysconfdir}/nginx/nginx.conf \
74 --http-log-path=${localstatedir}/log/nginx/access.log \
75 --error-log-path=${localstatedir}/log/nginx/error.log \
Brad Bishop6e60e8b2018-02-01 10:27:11 -050076 --http-client-body-temp-path=/run/nginx/client_body_temp \
77 --http-proxy-temp-path=/run/nginx/proxy_temp \
78 --http-fastcgi-temp-path=/run/nginx/fastcgi_temp \
79 --http-uwsgi-temp-path=/run/nginx/uwsgi_temp \
80 --http-scgi-temp-path=/run/nginx/scgi_temp \
Patrick Williamsddad1a12017-02-23 20:36:32 -060081 --pid-path=/run/nginx/nginx.pid \
82 --prefix=${prefix} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080083 --with-threads \
Patrick Williamsddad1a12017-02-23 20:36:32 -060084 --with-http_gzip_static_module \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050085 ${EXTRA_OECONF} ${PACKAGECONFIG_CONFARGS}
Patrick Williamsb48b7b42016-08-17 15:04:38 -050086}
87
88do_install () {
Patrick Williamsddad1a12017-02-23 20:36:32 -060089 oe_runmake 'DESTDIR=${D}' install
90 rm -fr ${D}${localstatedir}/run ${D}/run
91 if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
92 install -d ${D}${sysconfdir}/tmpfiles.d
93 echo "d /run/${BPN} - - - -" \
94 > ${D}${sysconfdir}/tmpfiles.d/${BPN}.conf
Andrew Geissler7f40b712020-05-15 14:09:53 -050095 echo "d ${localstatedir}/log/${BPN} 0755 root root -" \
Patrick Williamsddad1a12017-02-23 20:36:32 -060096 >> ${D}${sysconfdir}/tmpfiles.d/${BPN}.conf
97 fi
98 install -d ${D}${sysconfdir}/${BPN}
Andrew Geissler595f6302022-01-24 19:11:47 +000099 ln -rs ${D}${localstatedir}/run/${BPN} ${D}${sysconfdir}/${BPN}/run
Patrick Williamsddad1a12017-02-23 20:36:32 -0600100 install -d ${D}${NGINX_WWWDIR}
Brad Bishop23eaf032019-11-20 05:15:02 -0500101 mv ${D}${exec_prefix}/html ${D}${NGINX_WWWDIR}/
Patrick Williamsddad1a12017-02-23 20:36:32 -0600102 chown ${NGINX_USER}:www-data -R ${D}${NGINX_WWWDIR}
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500103
Patrick Williamsddad1a12017-02-23 20:36:32 -0600104 install -d ${D}${sysconfdir}/init.d
105 install -m 0755 ${WORKDIR}/nginx.init ${D}${sysconfdir}/init.d/nginx
106 sed -i 's,/usr/sbin/,${sbindir}/,g' ${D}${sysconfdir}/init.d/nginx
107 sed -i 's,/etc/,${sysconfdir}/,g' ${D}${sysconfdir}/init.d/nginx
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500108
Patrick Williamsddad1a12017-02-23 20:36:32 -0600109 install -d ${D}${sysconfdir}/nginx
110 install -m 0644 ${WORKDIR}/nginx.conf ${D}${sysconfdir}/nginx/nginx.conf
Brad Bishop19323692019-04-05 15:28:33 -0400111 sed -i 's,/etc/,${sysconfdir}/,g' ${D}${sysconfdir}/nginx/nginx.conf
Patrick Williamsddad1a12017-02-23 20:36:32 -0600112 sed -i 's,/var/,${localstatedir}/,g' ${D}${sysconfdir}/nginx/nginx.conf
113 sed -i 's/^user.*/user ${NGINX_USER};/g' ${D}${sysconfdir}/nginx/nginx.conf
Brad Bishop19323692019-04-05 15:28:33 -0400114 install -Dm 0644 ${WORKDIR}/default_server.site ${D}${sysconfdir}/nginx/sites-available/default_server
115 sed -i 's,/var/,${localstatedir}/,g' ${D}${sysconfdir}/nginx/sites-available/default_server
Patrick Williamsddad1a12017-02-23 20:36:32 -0600116 install -d ${D}${sysconfdir}/nginx/sites-enabled
Brad Bishop19323692019-04-05 15:28:33 -0400117 ln -s ../sites-available/default_server ${D}${sysconfdir}/nginx/sites-enabled/
118
119 install -m 0644 ${WORKDIR}/proxy_params ${D}${sysconfdir}/nginx/proxy_params
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500120
Patrick Williamsddad1a12017-02-23 20:36:32 -0600121 install -d ${D}${sysconfdir}/default/volatiles
122 install -m 0644 ${WORKDIR}/nginx-volatile.conf ${D}${sysconfdir}/default/volatiles/99_nginx
123 sed -i 's,/var/,${localstatedir}/,g' ${D}${sysconfdir}/default/volatiles/99_nginx
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124 sed -i 's,@NGINX_USER@,${NGINX_USER},g' ${D}${sysconfdir}/default/volatiles/99_nginx
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500125
Brad Bishop19323692019-04-05 15:28:33 -0400126 # cleanup configuration folder
127 rm ${D}${sysconfdir}/nginx/*.default
128
129 # add additional configuration folders
130 install -d ${D}${sysconfdir}/nginx/modules-available
131 install -d ${D}${sysconfdir}/nginx/modules-enabled
132 install -d ${D}${sysconfdir}/nginx/server-conf.d
133 install -d ${D}${sysconfdir}/nginx/conf.d
134
Patrick Williamsddad1a12017-02-23 20:36:32 -0600135 if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)};then
136 install -d ${D}${systemd_unitdir}/system
137 install -m 0644 ${WORKDIR}/nginx.service ${D}${systemd_unitdir}/system/
138 sed -i -e 's,@SYSCONFDIR@,${sysconfdir},g' \
139 -e 's,@LOCALSTATEDIR@,${localstatedir},g' \
140 -e 's,@SBINDIR@,${sbindir},g' \
Brad Bishop15ae2502019-06-18 21:44:24 -0400141 -e 's,@BASE_BINDIR@,${base_bindir},g' \
Patrick Williamsddad1a12017-02-23 20:36:32 -0600142 ${D}${systemd_unitdir}/system/nginx.service
143 fi
Andrew Geissler7f40b712020-05-15 14:09:53 -0500144
145 rm -rf ${D}${localstatedir}/log/
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500146}
147
Patrick Williams213cb262021-08-07 19:21:33 -0500148pkg_postinst:${PN} () {
Patrick Williamsddad1a12017-02-23 20:36:32 -0600149 if [ -z "$D" ]; then
150 if type systemd-tmpfiles >/dev/null; then
151 systemd-tmpfiles --create
152 elif [ -e ${sysconfdir}/init.d/populate-volatile.sh ]; then
153 ${sysconfdir}/init.d/populate-volatile.sh update
154 fi
155 fi
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500156}
157
Patrick Williams213cb262021-08-07 19:21:33 -0500158FILES:${PN} += " \
Patrick Williamsddad1a12017-02-23 20:36:32 -0600159 ${localstatedir}/ \
160 ${systemd_unitdir}/system/nginx.service \
161"
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500162
Patrick Williams213cb262021-08-07 19:21:33 -0500163CONFFILES:${PN} = " \
Patrick Williamsddad1a12017-02-23 20:36:32 -0600164 ${sysconfdir}/nginx/nginx.conf \
165 ${sysconfdir}/nginx/fastcgi.conf \
166 ${sysconfdir}/nginx/fastcgi_params \
167 ${sysconfdir}/nginx/koi-utf \
168 ${sysconfdir}/nginx/koi-win \
169 ${sysconfdir}/nginx/mime.types \
170 ${sysconfdir}/nginx/scgi_params \
171 ${sysconfdir}/nginx/uwsgi_params \
172 ${sysconfdir}/nginx/win-utf \
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500173"
174
175INITSCRIPT_NAME = "nginx"
176INITSCRIPT_PARAMS = "defaults 92 20"
177
178USERADD_PACKAGES = "${PN}"
Patrick Williams213cb262021-08-07 19:21:33 -0500179USERADD_PARAM:${PN} = " \
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500180 --system --no-create-home \
181 --home ${NGINX_WWWDIR} \
182 --groups www-data \
183 --user-group ${NGINX_USER}"