CentOS-8x+Linux-8中源码编译安装Nginx-1.20*详解版
=目录索引=
01)系统 &环境
运行环境:实验室虚拟环境
系统型号:CtenOS-8.4-x86_64
Linux版本:linux-8-x86_64
CPU&内存:4H + 4GB
系统内核:4.18.0-305.3.1.el8.x86_64
=主题内容=
02)安装前准备
- 1 更新
CentOS-8
软件包 :
dnf update
- 2 关闭系统防火墙:
systemctl stop firewalld
- 3 关闭防火墙开机自启动:
systemctl disable firewalld
- 4 关闭
SELINUX
:
sed -ri '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
setenforce 0
03)编译器 &【dev】库安装
- 1 安装
make
&wget
:
yum -y install gcc automake autoconf libtool make wget
- 2 安装
gcc
编译器:- 系统内置
gcc
版本查询:
- 系统内置
gcc --version
gcc (GCC) 10.2.1 20201112 (Red Hat 10.2.1-8) //版本够高够新,不用升级....
yum -y install gcc gcc-c++
- 2 安装
OpenSSL
开发库:ssl
模块,服务器使用SSL
安全证书需要,【–http_ssl_module】用于开启https
安全加密功能,依赖OpenSSL
开发库 :
yum -y install openssl openssl-devel
- 3 安装
PCRE
正则式表达库:nginx
必装模块【–http_rewrite_module】,基于正则匹配来实现重定向,依赖PCRE
库 :
yum -y install pcre pcre-devel
- 4 安装
zlib
压缩库:nginx
必装模块【–http_gzip_module】,用于针对HTTP
包中内容进行gzip
格式的压缩,依赖zlib
压缩库:
yum -y install zlib zlib-devel
04)编译安装【Nginx】
- 1 创建
nginxs
用户 & 用户属组:
useradd -s /sbin/nologin -M nginx
- 2 官网下载
nginx
最新稳定版:
mkdir lanmpp
cd /root/lanmpp
wget http://nginx.org/download/nginx-1.20.1.tar.gz
- 3 解压 & 删除
nginx
压缩包:
tar -xvf nginx-1.20.1.tar.gz
rm -rf nginx-1.20.1.tar.gz
- 4 预编译 & 配置
nginx
源码,使之生成可执行的二进制文件:
cd nginx-1.20.1/
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-pcre \
--with-file-aio \
--with-threads \
--with-mail \
--with-http_ssl_module \
--with-mail_ssl_module \
--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_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module
- 打印出现如下结果,则证明预编译 & 生成
makefile
二进制可执行文件成功…
Configuration summary
+ using threads
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx"
nginx configuration file: "/usr/local/nginx/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx