Nginx 1.25.4 编译安装
Nginx 1.25.4 源码编译安装
最新长期技术支持版本 nginx-1.25.4,官方下载源码包:
https://nginx.org/download/nginx-1.25.4.tar.gz
一键安装脚本
不啰嗦,脚本简单快速编译安装
#! /bin/bash #安装相关包 yum -y install gcc pcre-devel openssl-devel zlib-devel make wget #创建用户 id nginx || useradd -r -s /sbin/nologin nginx cd /usr/local/src/ #下载nginxan安装包 wget https://nginx.org/download/nginx-1.25.4.tar.gz #解压编译安装 tar xf nginx-1.25.4.tar.gz cd nginx-1.25.4/ ./configure --prefix=/apps/nginx \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre \ --with-stream \ --with-stream_ssl_module \ --with-stream_realip_module make -j `lscpu |grep '^CPU(s)' |awk '{print $2}'` && make install #设置权限 mkdir /apps/nginx/run/ -p chown -R nginx.nginx /apps/nginx #设置软链接 ln -s /apps/nginx/sbin/nginx /usr/sbin/ #设置开机自启服务文件 cat > /usr/lib/systemd/system/nginx.service <<EOF [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/apps/nginx/run/nginx.pid ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target EOF #准备相关自启配置文件 sed -i 's@^#pid .*/nginx.pid;@pid /apps/nginx/run/nginx.pid;@' /apps/nginx/conf/nginx.conf systemctl daemon-reload systemctl enable --now nginx