ubuntu下nginx的编译安装
nginx下载
下载地址:nginx: download
nginx编译环境的搭建
1
apt-get install gcc libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev gcc make -y
2 nginx之前的都是使用的openssl:1.1.1版本的编译
3 因为openssl:1.1.1的将要过期,现在默认安装的都是openssl:3.x的
4 所以有可能编译会报错,解决的话需要下载编译openssl:1.1.1
5 下载之后只需要编译即可
openssl下载地址:Old Releases | Library (openssl-library.org)
编译
1
tar zxvf nginx-1.18.0.tar.gz
2 cd nginx-1.18.0
3 ./configure \
4 --with-cc-opt='-g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-
protector-strong -Wformat -Wno-error -Werror=deprecated-declarations -fPIC -Wdate-time -
D_FORTIFY_SOURCE=2' \
5 --with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-
z,relro -Wl,-z,now -fPIC' \
6 --prefix=/usr/share/nginx \
7 --conf-path=/etc/nginx/nginx.conf \
8 --http-log-path=/var/log/nginx/access.log \
9 --error-log-path=/var/log/nginx/error.log \
10 --lock-path=/var/lock/nginx.lock \
11 --pid-path=/run/nginx.pid \
12 --modules-path=/usr/lib/nginx/modules \
13 --http-client-body-temp-path=/var/lib/nginx/body \
14 --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
15 --http-proxy-temp-path=/var/lib/nginx/proxy \
16 --http-scgi-temp-path=/var/lib/nginx/scgi \
17 --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
18 --with-compat \
19 --with-debug \
20 --with-pcre-jit \
21 --with-http_ssl_module \
22 --with-http_stub_status_module \
23 --with-http_realip_module \
24 --with-http_auth_request_module \
25 --with-http_v2_module \
26 --with-http_dav_module \
27 --with-http_slice_module \
28 --with-threads \
29 --with-http_addition_module \
30 --with-http_gunzip_module \
31 --with-http_gzip_static_module \
32 --with-http_sub_module
33 --with-openssl=/home/dawenzi/openssl-1.1.1w
安装
1
make
2 make install
3
启动nginx
1
/usr/share/nginx/sbin/nginx
2 #或者配置下面的启动
3 systemctl daemon-reload
4 systemctl start nginx
配置systemctl配置文件
1
/usr/lib/systemd/system/nginx.service
2
3 [Unit]
4 Description=nginx - high performance web server
5 Documentation=http://nginx.org/en/docs/
6 After=network-online.target remote-fs.target nss-lookup.target
7 Wants=network-online.target
8
9 [Service]
10 Type=forking
11 PIDFile=/run/nginx.pid
12 ExecStartPre=/usr/share/nginx/sbin/nginx -t
13 ExecStart=/usr/share/nginx/sbin/nginx
14 ExecReload=/usr/share/nginx/sbin/nginx -s reload
15 ExecStop=/usr/share/nginx/sbin/nginx -s stop
16 ExecQuit=/usr/share/nginx/sbin/nginx -s quit
17 PrivateTmp=true
18
19 [Install]
20 WantedBy=multi-user.target
21