Ticket #1641: build_nginx.sh

File build_nginx.sh, 4.4 KB (added by Ivan Aksamentov, 8 years ago)

Bash script to build nginx 1.15.3 with LTO

Line 
1#!/bin/bash -e
2
3# sudo apt-get install build-essential zlib1g-dev libpcre3-dev uuid-dev
4
5set -x
6
7export NUM_JOBS="$(($(nproc) * 2))"
8export SRC_DIR=${HOME}/src
9
10NAME=nginx
11VERSION=1.15.3
12URL=https://nginx.org/download/nginx-${VERSION}.tar.gz
13
14NAME=${NAME}-${VERSION}
15SOURCE_DIR=${SRC_DIR}/${NAME}
16BUILD_DIR=${SOURCE_DIR}
17ARCHIVE_FILE=${NAME}.tar.gz
18URL=https://nginx.org/download/${ARCHIVE_FILE}
19
20OPENSSL_VERSION=1.1.1
21OPENSSL_SOURCE_DIR=${SOURCE_DIR}/openssl-${OPENSSL_VERSION}
22OPENSSL_ARCHIVE_FILE=openssl-${OPENSSL_VERSION}.tar.gz
23OPENSSL_URL=https://www.openssl.org/source/${OPENSSL_ARCHIVE_FILE}
24
25pushd ${SRC_DIR}
26 if [ ! -f ${ARCHIVE_FILE} ]; then
27 wget ${URL}
28 fi
29
30 if [ ! -d ${SOURCE_DIR} ]; then
31 tar xvf ${ARCHIVE_FILE}
32
33 pushd ${SOURCE_DIR}
34 # Remove nginx name and version info from headers and pages
35 sed -i -e 's/static u_char ngx_http_server_string\[\] = "Server: nginx" CRLF;/static u_char ngx_http_server_string[] = "" CRLF;/g' src/http/ngx_http_header_filter_module.c
36 sed -i -e 's/static u_char ngx_http_server_full_string\[\] = "Server: " NGINX_VER CRLF;/static u_char ngx_http_server_full_string[] = "" CRLF;/g' src/http/ngx_http_header_filter_module.c
37 sed -i -e 's/static u_char ngx_http_server_build_string\[\] = "Server: " NGINX_VER_BUILD CRLF;/static u_char ngx_http_server_build_string[] = "" CRLF;/g' src/http/ngx_http_header_filter_module.c
38
39 URL_BROTLI=https://github.com/google/ngx_brotli
40 URL_ECHO=https://github.com/openresty/echo-nginx-module
41 URL_CACHE_PURGE=https://github.com/FRiCKLE/ngx_cache_purge
42 URL_HEADERS_MORE=https://github.com/openresty/headers-more-nginx-module
43
44 git clone --recursive --depth 1 ${URL_BROTLI} ngx_brotli
45 git clone --recursive --depth 1 ${URL_ECHO} ngx_echo
46 git clone --recursive --depth 1 ${URL_CACHE_PURGE} ngx_cache_purge
47 git clone --recursive --depth 1 ${URL_HEADERS_MORE} ngx_headers_more
48
49 if [ ! -f ${OPENSSL_ARCHIVE_FILE} ]; then
50 wget ${OPENSSL_URL}
51 fi
52
53 if [ ! -d ${OPENSSL_SOURCE_DIR} ]; then
54 tar xvf ${OPENSSL_ARCHIVE_FILE}
55 fi
56 popd
57 fi
58popd
59
60mkdir -p ${BUILD_DIR}
61pushd ${BUILD_DIR}/
62
63
64export CFLAGS='-O2 -flto -march=native -fomit-frame-pointer -fPIE -pie -fstack-protector-strong -D_FORTIFY_SOURCE=2'
65export LDFLAGS='-fPIE -pie -flto -Wl,-flto -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now'
66
67# Use gold-enabled binutils for flto
68export AR=gcc-ar
69export RANLIB=gcc-ranlib
70export NM=gcc-nm
71
72
73${SOURCE_DIR}/configure \
74--prefix=/usr/share/nginx \
75--sbin-path=/usr/sbin/nginx \
76--pid-path=/run/nginx.pid \
77--conf-path=/etc/nginx/nginx.conf \
78--lock-path=/var/lock/nginx.lock \
79--modules-path=/usr/lib/nginx/modules \
80--http-log-path=/var/log/nginx/access.log \
81--error-log-path=/var/log/nginx/error.log \
82--build=Ubuntu \
83--http-client-body-temp-path=/var/lib/nginx/body \
84--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
85--http-proxy-temp-path=/var/lib/nginx/proxy \
86--http-scgi-temp-path=/var/lib/nginx/scgi \
87--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
88--group=www-data \
89--user=www-data \
90--add-module=${SOURCE_DIR}/ngx_brotli \
91--add-module=${SOURCE_DIR}/ngx_echo \
92--add-module=${SOURCE_DIR}/ngx_cache_purge \
93--add-module=${SOURCE_DIR}/ngx_headers_more \
94--with-compat \
95--with-file-aio \
96--with-threads \
97--with-stream \
98--with-openssl=${OPENSSL_SOURCE_DIR} \
99--with-openssl-opt=enable-tls1_3 \
100--with-http_auth_request_module \
101--with-http_degradation_module \
102--with-http_gunzip_module \
103--with-http_gzip_static_module \
104--with-http_realip_module \
105--with-http_secure_link_module \
106--with-http_slice_module \
107--with-http_ssl_module \
108--with-http_stub_status_module \
109--with-http_sub_module \
110--with-http_v2_module \
111--with-mail_ssl_module \
112--with-stream \
113--with-stream_realip_module \
114--with-stream_ssl_module \
115--with-stream_ssl_preread_module \
116--without-http_auth_basic_module \
117--without-http_autoindex_module \
118--without-http_browser_module \
119--without-http_empty_gif_module \
120--without-http_geo_module \
121--without-http_memcached_module \
122--without-http_scgi_module \
123--without-http_split_clients_module \
124--without-http_ssi_module \
125--without-http_userid_module \
126--without-http_uwsgi_module \
127--with-cc-opt="${CFLAGS}" \
128--with-ld-opt="${LDFLAGS}"
129
130
131make -j ${NUM_JOBS}
132sudo make -j ${NUM_JOBS} install
133
134popd