-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-nginx.sh
executable file
·142 lines (125 loc) · 4.38 KB
/
build-nginx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# 获取linux发行版本
lsb_dist=$( grep -Eio "Ubuntu|Debian|Alpine|Kernel" /etc/issue | head -n1 )
# 包管理器
if [ "$lsb_dist" = "Kernel" ]; then
# 安装依赖
yum -y update
yum -y groupinstall "Development Tools"
elif [ "$lsb_dist" = "Ubuntu" ]; then
# 安装依赖
sed 's/\(deb\|security\|snapshot\).debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list -i
apt-get update
apt-get -y install curl build-essential autoconf
elif [ "$lsb_dist" = "Debian" ]; then
# 安装依赖
sed 's/\(deb\|security\|snapshot\).debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list -i
apt-get update
apt-get -y install curl build-essential autoconf
elif [ "$lsb_dist" = "Alpine" ]; then
# 更换源
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
# 安装依赖
apk add --no-cache --virtual .build curl gcc libc-dev make openssl-dev pcre-dev zlib-dev linux-headers libxslt-dev gd-dev geoip-dev perl-dev libedit-dev mercurial bash alpine-sdk findutils
else
echo 'error: unknow system'
exit 1
fi
mkdir -p /home/src
curl -L http://nginx.org/download/nginx-1.18.0.tar.gz -o /home/src/nginx-1.18.0.tar.gz
curl -L https://www.openssl.org/source/openssl-1.1.1g.tar.gz -o /home/src/openssl-1.1.1g.tar.gz
curl -L http://www.zlib.net/zlib-1.2.11.tar.gz -o /home/src/zlib-1.2.11.tar.gz
curl -L https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz -o /home/src/pcre-8.44.tar.gz
mkdir -p /home/nginx/temp
tar -zxvf /home/src/nginx-1.18.0.tar.gz -C /home/nginx
tar -zxvf /home/src/openssl-1.1.1g.tar.gz -C /home/src
tar -zxvf /home/src/zlib-1.2.11.tar.gz -C /home/src
tar -zxvf /home/src/pcre-8.44.tar.gz -C /home/src
mv /home/src /home/nginx/
cd /home/nginx/src/pcre-8.44 && autoreconf -vfi
cd /home/nginx/nginx-1.18.0
# nginx configure
./configure \
--prefix=.. \
--sbin-path=sbin/nginx \
--modules-path=modules \
--conf-path=conf/nginx.conf \
--error-log-path=logs/error.log \
--http-log-path=logs/access.log \
--pid-path=run/nginx.pid \
--lock-path=run/nginx.lock \
--http-client-body-temp-path=temp/client_temp \
--http-proxy-temp-path=temp/proxy_temp \
--http-fastcgi-temp-path=temp/fastcgi_temp \
--http-uwsgi-temp-path=temp/uwsgi_temp \
--http-scgi-temp-path=temp/scgi_temp \
--user=nginx \
--group=nginx \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-cc-opt='-Os -fomit-frame-pointer -Wno-error' \
--with-ld-opt='-Wl,--as-needed,-rpath,../lib -L../lib -lstdc++ -ldl' \
--with-pcre=../src/pcre-8.44 \
--with-openssl=../src/openssl-1.1.1g \
--with-zlib=../src/zlib-1.2.11
# --with-zlib=../src/zlib-1.2.11 \
# --add-module=../src/nginx-rtmp-module
# 变更参数
# --with-cc-opt='-Os -fomit-frame-pointer' \
# --with-ld-opt=-Wl,--as-needed
# --add-module=../nginx-rtmp-module
make -j2 && make install
if [ $? = 0 ]; then
echo 'nginx build success'
else
echo 'nginx build error'
exit 1
fi
# 后置操作
tee /home/nginx/nginx <<-'EOF'
#!/bin/bash
# nginx sbin (必须指定该目录)
cd /usr/share/nginx/sbin
if [ ! -n "$(grep -w nginx /etc/passwd)" ]; then
# alpine
if [ -r /etc/alpine-release ]; then
addgroup -g 202 -S nginx
adduser -S -D -H -u 202 -h /var/cache/nginx -s /sbin/nologin -G nginx -g nginx nginx
# Debian & Ubuntu
elif [ -n "$(grep -Eio "Ubuntu|Debian" /etc/issue)" ]; then
addgroup --system --gid 202 nginx
adduser --system --disabled-login --ingroup nginx --no-create-home --gecos "nginx user" --shell /bin/false --uid 202 nginx
# centos
elif [ -r /etc/redhat-release ]; then
groupadd --system --gid 202 nginx
useradd --system -g nginx --no-create-home --home /nonexistent --comment "nginx user" --shell /bin/false --uid 202 nginx
else
echo 'error: Unknow system, Cannot create nginx user'
exit 1;
fi
fi
exec ./nginx "$@"
EOF
chmod -R 755 /home/nginx/nginx